While compiling my code, it produces "Incompatible types: 'String' and 'Byte'. I do not see where I define variable as 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;
unitA
for i:= 1 to 10 do
begin
portType:=TDatabaseManager.getPortType('Port'+i);
end;
Please advise
In this line:
getPortType('Port'+i);
You are trying to append an integer directly to a string literal. That does not work. You need to change it to this instead:
getPortType('Port'+IntToStr(i));