Différence de format de String entre une StringGrid.Cells[aCol,aRow]et un array_of_String[aRow]
Bonjour,
Je transforme une image en String (normalement AnsiString) mais une déclaration String suffit :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| function TmySQLtoSGtoSQL.SQLBlobToStr(aQuery : TZQuery; aField : TField) : String;
{public}
{String or AnsiString ?}
var
aStream : TMemoryStream;
begin
Result := '';
with aQuery do
if not(aField.isNull) then begin
try
aStream := TMemoryStream.Create;
TBlobField(aField).SaveToStream(aStream);
Result := MemStreamToString(aStream);
finally
aStream.Free;
end;
end;
end; |
Puis réciproquement la String en Image
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| function TmySQLtoSGtoSQL.StrBlobToImage(aStr : String; aImage: TImage): Boolean;
var
aStream : TMemoryStream;
begin
Result := False;
if aStr <> '' then
try
aStream := TMemoryStream.Create;
try
if StringToMemStream(aStr, aStream) then begin
aStream.Position := 0;
aImage.Picture.LoadFromStream(aStream);
Result := True;
end;
except
Result := False;
end;
finally
aStream.Free;
end;
end; |
Un test "ordinaire" fonctionne :
Code:
1 2 3 4 5 6 7
| {sTmp : String;}
with mySQLtoSGtoSQL1 do begin
//Envoi du Field SQL ds une chaine
sTmp := SQLBlobToStr(ZQueryLOCK,Fields[ca_caLOGO]);
//Envoi d'une chaine dans l'image;
if sTmp <> '' then StrBlobToImage(sTmp, Image1);
end; |
Maintenant, si je place mes sTmp dans des cellules d'une TStringGrid cela ne fonctionne plus. Pour que cela fonctionne, il faut que j'associe mes sTmp dans un aArray (array of string). Je suis en {$mode objfpc}{$H+}
Code:
1 2 3 4
| with mySQLtoSGtoSQL1 do begin
StrBlobToImage(aArray[iRow], Image1); {OK}
StrBlobToImage(Cells[sg_caLOGO, iRow], Image2); {No !!!!!!!!!}
end; |
Les TStringGrids.Cells[aCol, aRow] ne sont pas des String de même nature que les aArray[aRow] ?
Un Showmessage( IntToStr(length(aArray[iRow]))+'-'+IntToStr(length(Cells[sg_caLOGO, iRow]))); renvoie 1010-8 donc le remplissage de Cells avec la même méthode que l'array[aRow] ne fonctionne pas. J'en déduis -peut-être bêtement- que la nature des String n'est pas identique. Est-ce un raisonnement erroné ? Je précise que dans le TStringGrid, j'utilise des TColumns dont j'ai modifié la MaxSize... au cas où... mais sans succès.
Une bonne âme peut m'expliquer ?
Cordialement. Gilles