Thema: Delphi Save record to BLOB

Einzelnen Beitrag anzeigen

nanix
(Gast)

n/a Beiträge
 
#1

Save record to BLOB

  Alt 4. Dez 2009, 23:01
Datenbank: Absolute Database • Zugriff über: BLOB
Hello i wrote this code,but its got a bug that i cant find
i write to record but then if i save it OK if load it from BLOB OK.But if i close program and load it it won't load the things i saved.

Why is that?


Delphi-Quellcode:
TSensor=record
    Name:String[20];
    Value:String[20];
    Min:String[20];
    Max:String[20];
    Average:String[20];
    Delta:String[20];
    Offset:String[20];
  end;

  TMonitor=record
    Name:String[20];
    Sensor:Array [0..2] of TSensor
  end;

  TMonitoring=record
    Monitoring:Array [0..1] of TMonitor;
  end;



var
Monitoring:TMonitoring;
Monitor:TMonitor;
Sensor:TSensor;


procedure TDBSync.SavetoBLOB(ABSTable:TABSTable;Memo:TMemo);
var
   blobF : TBlobField;
   bs : TStream;
begin

 {for I := 0 to High(Monitoring.Monitoring) - 1 do begin
for k := 0 to High(Monitor.Sensor) - 1 do begin     }


Monitoring.Monitoring[0].Name:='Monitor0';
Monitor.Sensor[0].Name:='Sensor0';
Monitor.Sensor[0].Value:='A';
Monitor.Sensor[0].Min:='B';
Monitor.Sensor[0].Max:='C';
Monitor.Sensor[0].Average:='D';
Monitor.Sensor[0].Delta:='E';
Monitor.Sensor[0].Offset:='F';

Monitoring.Monitoring[1].Name:='Monitor0';
Monitor.Sensor[1].Name:='Sensor0';
Monitor.Sensor[1].Value:='A';
Monitor.Sensor[1].Min:='B';
Monitor.Sensor[1].Max:='C';
Monitor.Sensor[1].Average:='D';
Monitor.Sensor[1].Delta:='E';
Monitor.Sensor[1].Offset:='F';

   ABSTable.Insert;

   blobF := ABSTable.FieldByName('BLOB') as TBlobField;
   bs := ABSTable.CreateBlobStream(blobF, bmWrite) ;
   try
     bs.Write(Monitoring,SizeOf(Monitoring)) ;

   finally

     bs.Free;
     ABSTable.Post;
   end;
end;



procedure TDBSync.LoadfromBLOB(ABSTable:TABSTable;Memo:TMemo);
var
   blobF : TBlobField;
   bs : TStream;
   i,k:integer;
begin
   if ABSTable.FieldByName('BLOB').IsBlob then
   begin
     blobF := ABSTable.FieldByName('BLOB') as TBlobField;
     bs := ABSTable.CreateBlobStream(blobF, bmRead);
     try
       bs.Read(Monitoring,sizeof(TMonitoring)) ;
     finally
       bs.Free;
     end;
   end;

 for I := 0 to High(Monitoring.Monitoring) - 1 do begin
 for k := 0 to High(Monitor.Sensor) - 1 do begin


 Memo.Lines.Add('* '+Monitoring.Monitoring[i].Name);
 Memo.Lines.Add(' -'+Monitor.Sensor[k].Name);
 Memo.Lines.Add(' -'+Monitor.Sensor[k].Value);
 Memo.Lines.Add(' -'+Monitor.Sensor[k].Min);
 Memo.Lines.Add(' -'+Monitor.Sensor[k].Max);
 Memo.Lines.Add(' -'+Monitor.Sensor[k].Average);
 Memo.Lines.Add(' -'+Monitor.Sensor[k].Delta);
 Memo.Lines.Add(' -'+Monitor.Sensor[k].Offset);
 end;
end;
end;
  Mit Zitat antworten Zitat