错误:字符串和字节不兼容

时间:2014-10-21 08:20:01

标签: delphi-2007

在编译我的代码时,它会产生"不兼容的类型:' String'和' Byte' 我没有看到我将变量定义为byte。

unitB

function TDatabaseManager.getPortType(portNo:string):String;
var
   SQLQuery:TSQLQuery;
begin
   result := '';
   SQLQuery := TSQLQuery.Create(Nil);
try
    SQLQuery.SQLConnection := FSQLConnection;
    SQLQuery.SQL.Clear;
    SQLQuery.SQL.Text:= 'SELECT '+portNo+' FROM tblmk6ecpu_setupindex AS t1, tblmk6ecpu_setup AS t2';
    SQLQuery.SQL.Text := SQLQuery.SQL.Text + ' WHERE t1.BatchNumber = '''+BatchNo+ ''' AND t1.MfgCode = t2.MfgCode';
    SQLQuery.SQL.Text := SQLQuery.SQL.Text + ' ORDER By t1.SetupId DESC';
    SQLQuery.Active:=true;
    if (not(SQLQuery.IsEmpty())) then
        result := VarToStr(SQLQuery.FieldValues[portNo]);
finally
    SQLQuery.free;
end;
end;

的安盟

for i:= 1 to 10 do
    begin
      portType:=TDatabaseManager.getPortType('Port'+i);
    end;

请告知

1 个答案:

答案 0 :(得分:2)

在这一行:

getPortType('Port'+i);

您正尝试将整数直接附加到字符串文字。这不起作用。您需要将其更改为:

getPortType('Port'+IntToStr(i));