Scalabium Software |
|
| Knowledge for your independence'. | |
#65: How can I save/restore the component into BLOB-field? |
|
Sometimes in applications you must save the component into BLOB-field of the own table and in run-time to restore it. For example, to save the report form and in run-time the end-user will select the wished report before report generation. The next two procedure allows to save the component with all properties and restore it. procedure SaveCompToBlob(AField: TBlobField; AComponent: TComponent);
var
Stream: TBlobStream;
CompName: string;
begin
CompName := Copy(AComponent.ClassName, 2, 99);
Stream := TBlobStream.Create(AField, bmWrite);
try
Stream.WriteComponentRes(CompName, AComponent);
finally
Stream.Free;
end;
end;
procedure LoadCompFromBlob(AField: TBlobField; AComponent: TComponent);
var
Stream: TBlobStream;
i: integer;
begin
try
Stream := TBlobStream.Create(AField, bmRead);
try
{delete the all child components}
for i := AComponent.ComponentCount - 1 downto 0 do
AComponent.Components[i].Free;
Stream.ReadComponentRes(AComponent);
finally
Stream.Free;
end;
except
on EFOpenError do {nothing};
end;
end;
|
|
Copyright© 1998-2025, Scalabium
Software. All rights reserved. |