best way to fill oracle raw field with TOracleDataSet

tschuk

Member
Hello,
I'm facing some trouble with raw field's in oracle. I made a simple test case with a raw field with 504 Bytes:

>>>>>>>>>
create table test (r4 RAW(504));
>
procedure TForm1.Button1Click(Sender: TObject);
var
koeff126: array[0..125] of Single;
I: Integer;
begin
for I := 0 to 126 - 1 do
koeff126 := I;
with OracleDataSet1 do
begin
Insert;
WriteKoeff(FieldByName('r4'), koeff126, 126);
Post;
end;
end;

procedure TForm1.WriteKoeff(fld: TField; koeff: array of Single;
nKoeff: Integer);
var
aMS: TMemoryStream;
i: Integer;
s: String;
pB: PByte;
begin
aMS := nil;

try
aMS := TMemoryStream.Create;
// Werte erstmal in Stream speichern
for i := 0 to nKoeff - 1 do
aMS.Write(koeff, sizeof(Single));
// aus dem Stream einen HEXADEZIMAL-String erzeugen
s := '';
pB := PByte(aMS.Memory);
for i := 0 to aMS.Size - 1 do
begin
s := s + IntToHex(pB^,2);
Inc (pB);
end;
fld.AsString := s;
finally
if aMS nil then FreeAndNil(aMS);
end;
end;
 
Can you check Length(s) before you assign it to fld.AsString? Can you also check if it has the expected hexadecimal string value?
 
Hello Marco,

thanks for your reply, Length(s) evaluates to 1008, s contains a valid HEX-String (please ignore the single quotes, they are from the expression evaluator):

>>>>>>>>>>>>>>>>>>>>>
'000000000000803F0000004000004040000080400000A0400000C0400000E0400000004100001041000020410000304100004041000050410000604100007041000080410000884100009041000098410000A0410000A8410000B0410000B8410000C0410000C8410000D0410000D8410000E0410000E8410000F0410000F84100000042000004420000084200000C4200001042000014420000184200001C4200002042000024420000284200002C4200003042000034420000384200003C4200004042000044420000484200004C4200005042000054420000584200005C4200006042000064420000684200006C4200007042000074420000784200007C42000080420000824200008442000086420000884200008A4200008C4200008E42000090420000924200009442000096420000984200009A4200009C4200009E420000A0420000A2420000A4420000A6420000A8420000AA420000AC420000AE420000B0420000B2420000B4420000B6420000B8420000BA420000BC420000BE420000C0420000C2420000C4420000C6420000C8420000CA420000CC420000CE420000D0420000D2420000D4420000D6420000D8420000DA420000DC420000DE420000E0420000E2420000E4420000E6420000E8420000EA420000EC420000EE420000F0420000F2420000F4420000F6420000F8420000FA42'
>>>>>>>>>>>>>>>>>>>>>

regards
Frank
 
Back
Top