Autor Beitrag
cartridge
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 209

Win XP
D4 Prof,D6 Prof
BeitragVerfasst: Di 07.08.07 19:40 
Hallo Kollegen!

Leider habe ich es immer noch nicht hin bekommen, Daten in ein BLOB- Feld zu schreiben, bzw daraus zu lesen.

Mein Ansatz
(aBerParams ist jeweils ein Record):
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
//Die Lesemethode:
function BerParamsFromField(aField: TField; var aBerParams:
  TBerechnungsParameter): Boolean;
var
  lStream: TAdoBlobStream;
begin
  Result:= false;
  if not aField.IsBlob or not aField.DataSet.Active then exit;
  try
    lStream:= TAdoBlobStream.Create(aField as TBlobField,bmRead);
    lStream.ReadBuffer(aBerParams,(aField as TBlobField).BlobSize);
    Result:= true;
  finally
    lStream.Free;
  end;
end;

//Dies ist die Schreibmethode:
function BerParamsToField(aField: TField; var aBerParams: TBerechnungsParameter): Boolean;
var
  lStream: TAdoBlobStream;
begin
  Result:= false;
  if not aField.IsBlob or not aField.DataSet.Active then exit;
  try
    lStream:= TAdoBlobStream.Create((aField as TBlobField),bmWrite);
    lStream.Write(aBerParams,SizeOf(aBerParams));
    Result:= true;
  finally
    lStream.Free;
  end;
end;


Wahrscheinlich ist es ganz einfach.
Vielen Dank für jeden Lösungsansatz!
Gruß Ingo

_________________
====================
Na klar bin ich sicher!!! Oder..?
bockwurst
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 191

win98 /XP
D1 D5 Prof DE2005PE
BeitragVerfasst: Do 09.08.07 16:22 
so hatte es es mal gemacht

Du kannst es aber auch einfacher so machen:

Table_Daten_Blobfeldname.ASSTRING :=string;
string := Table_Daten_Blobfeldname.ASSTRING;



ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
procedure TActionListe.SaveToBlob(Name: TBlobField);
var MyStream: TBlobStream;
    i,j: smallint;
begin
  MyStream:=TBlobStream.Create(Name, bmWrite);
  i:=Count-1;
  MyStream.Write(i, sizeof(i));

  for i:= 0 to Count-1 do
    TAction(Items[i]).Store(MyStream);

  if(ZDaten<>nil)and(ZDaten.Count>0)
    then begin
           with ZDaten do
           begin
             i:= Count;
             MyStream.Write(i, SizeOf(i));
             if(Count>0)then
             begin
               for i := 0 to Count-1 do
               begin
                 j:=Wert[i];
                 MyStream.Write(j, SizeOf(j));
               end;
             end;
           end;
         end
    else begin
           i:= 0;
           MyStream.Write(i, SizeOf(i));
         end;

  (*Abfragedaten*)
  if(ADaten<>nil)and(ADaten.Count>0)
    then begin
           with ADaten do
           begin
             i:= Count;
             MyStream.Write(i, SizeOf(i));
             if(Count>0)then
             begin
               for i := 0 to Count-1 do
               begin
                 xTemp:= ADaten[i];
                 MyStream.Write(xTemp, length(xTemp)+1);
               end;
             end;
           end;
         end
    else begin
           i:= 0;
           MyStream.Write(i, SizeOf(i));
         end;
  MyStream.Free;
end;

procedure TActionListe.LoadFromBlob(Name: TBlobField);
var MyStream: TBlobStream;
    Anzahl,i,j: smallint;
begin
  MyStream:=TBlobStream.Create(Name, bmRead);
  Anzahl:= MyStream.Seek(0,2);
  MyStream.Free;
  if(Anzahl=0)then exit;
  MyStream:=TBlobStream.Create(Name, bmRead);
  MyStream.Read(Anzahl, sizeof(Anzahl));
  for i:=0 to Anzahl do
  begin
    Action:=TAction.Create('X');
    Action.Load(MyStream);
    Add(Action);
  end;

  MyStream.Read(Anzahl, SizeOf(Anzahl));
  if(Anzahl>0)then
  begin
    ZDaten:= TIntegerListe.Create;
    with ZDaten do
      for i:= 1 to Anzahl do
      begin
        MyStream.Read(j, SizeOf(j));
        Wert[-1]:=j;
      end;
  end;

  (*Abfragedaten*)
  MyStream.Read(Anzahl, SizeOf(Anzahl));
  if(Anzahl>0)then
  begin
    ADaten:= TStringList.Create;
    with ADaten do
      for i:= 1 to Anzahl do
      begin
        MyStream.Read(xTemp[0], 1);
        MyStream.Read(xTemp[1], byte(xTemp[0]));
        Add(xTemp);
      end;
  end;
  MyStream.Free;
end;