mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-28 15:40:22 +02:00
* Delta stream support
This commit is contained in:
parent
7bcc949308
commit
972b5181eb
@ -1462,6 +1462,8 @@ function DefaultInitHandler(Instance: TComponent; RootAncestor: TClass): Boolean
|
|||||||
try
|
try
|
||||||
{$endif}
|
{$endif}
|
||||||
result:=doinit(Instance.ClassType);
|
result:=doinit(Instance.ClassType);
|
||||||
|
if Result then
|
||||||
|
Instance.ReadDeltaState;
|
||||||
{$ifdef FPC_HAS_FEATURE_THREADING}
|
{$ifdef FPC_HAS_FEATURE_THREADING}
|
||||||
finally
|
finally
|
||||||
GlobalNameSpace.EndWrite;
|
GlobalNameSpace.EndWrite;
|
||||||
|
@ -1808,6 +1808,8 @@ type
|
|||||||
TReadWriteStringPropertyEvent = procedure(Sender:TObject;
|
TReadWriteStringPropertyEvent = procedure(Sender:TObject;
|
||||||
const Instance: TPersistent; PropInfo: PPropInfo;
|
const Instance: TPersistent; PropInfo: PPropInfo;
|
||||||
var Content:string) of object;
|
var Content:string) of object;
|
||||||
|
TGetStreamProc = procedure (const S: TStream) of object;
|
||||||
|
TGetDeltaStreamsEvent = procedure (Sender: TObject; Proc: TGetStreamProc; var Handled: Boolean) of object;
|
||||||
|
|
||||||
|
|
||||||
{ TReader }
|
{ TReader }
|
||||||
@ -1888,6 +1890,7 @@ type
|
|||||||
procedure ReadListBegin;
|
procedure ReadListBegin;
|
||||||
procedure ReadListEnd;
|
procedure ReadListEnd;
|
||||||
function ReadRootComponent(ARoot: TComponent): TComponent;
|
function ReadRootComponent(ARoot: TComponent): TComponent;
|
||||||
|
function ReadComponentDeltaRes(Instance: TComponent; const DeltaCandidates: array of Ansistring; const Proc: TGetStreamProc): TComponent;
|
||||||
function ReadVariant: Variant;
|
function ReadVariant: Variant;
|
||||||
procedure ReadSignature;
|
procedure ReadSignature;
|
||||||
function ReadString: RawBytestring;
|
function ReadString: RawBytestring;
|
||||||
@ -2382,6 +2385,7 @@ type
|
|||||||
|
|
||||||
TBasicAction = class;
|
TBasicAction = class;
|
||||||
|
|
||||||
|
|
||||||
{ TComponent }
|
{ TComponent }
|
||||||
|
|
||||||
TComponent = class(TPersistent,IUnknown,IInterfaceComponentReference)
|
TComponent = class(TPersistent,IUnknown,IInterfaceComponentReference)
|
||||||
@ -2395,6 +2399,7 @@ type
|
|||||||
FVCLComObject: Pointer;
|
FVCLComObject: Pointer;
|
||||||
FComponentState: TComponentState;
|
FComponentState: TComponentState;
|
||||||
FDObservers : TObservers;
|
FDObservers : TObservers;
|
||||||
|
FOnGetDeltaStreams: TGetDeltaStreamsEvent;
|
||||||
function GetComObject: IUnknown;
|
function GetComObject: IUnknown;
|
||||||
function GetComponent(AIndex: Integer): TComponent;
|
function GetComponent(AIndex: Integer): TComponent;
|
||||||
function GetComponentCount: Integer;
|
function GetComponentCount: Integer;
|
||||||
@ -2411,6 +2416,9 @@ type
|
|||||||
procedure WriteTop(Writer: TWriter);
|
procedure WriteTop(Writer: TWriter);
|
||||||
protected
|
protected
|
||||||
FComponentStyle: TComponentStyle;
|
FComponentStyle: TComponentStyle;
|
||||||
|
procedure GetDeltaStreams(aProc: TGetStreamProc); virtual;
|
||||||
|
procedure ReadDeltaStream(const S: TStream);
|
||||||
|
procedure ReadDeltaState; virtual;
|
||||||
procedure ChangeName(const NewName: TComponentName);
|
procedure ChangeName(const NewName: TComponentName);
|
||||||
procedure DefineProperties(Filer: TFiler); override;
|
procedure DefineProperties(Filer: TFiler); override;
|
||||||
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); dynamic;
|
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); dynamic;
|
||||||
@ -2488,6 +2496,7 @@ type
|
|||||||
property Owner: TComponent read FOwner;
|
property Owner: TComponent read FOwner;
|
||||||
property VCLComObject: Pointer read FVCLComObject write FVCLComObject;
|
property VCLComObject: Pointer read FVCLComObject write FVCLComObject;
|
||||||
Property Observers : TObservers Read GetObservers;
|
Property Observers : TObservers Read GetObservers;
|
||||||
|
property OnGetDeltaStreams: TGetDeltaStreamsEvent read FOnGetDeltaStreams write FOnGetDeltaStreams;
|
||||||
published
|
published
|
||||||
property Name: TComponentName read FName write SetName stored False;
|
property Name: TComponentName read FName write SetName stored False;
|
||||||
property Tag: PtrInt read FTag write FTag default 0;
|
property Tag: PtrInt read FTag write FTag default 0;
|
||||||
@ -2811,7 +2820,6 @@ type
|
|||||||
TIntToIdent = function(Int: Longint; var Ident: string): Boolean;
|
TIntToIdent = function(Int: Longint; var Ident: string): Boolean;
|
||||||
TFindGlobalComponent = function(const Name: string): TComponent;
|
TFindGlobalComponent = function(const Name: string): TComponent;
|
||||||
TInitComponentHandler = function(Instance: TComponent; RootAncestor : TClass): boolean;
|
TInitComponentHandler = function(Instance: TComponent; RootAncestor : TClass): boolean;
|
||||||
TGetStreamProc = procedure (const S: TStream) of object;
|
|
||||||
|
|
||||||
var
|
var
|
||||||
MainThreadID: TThreadID;
|
MainThreadID: TThreadID;
|
||||||
|
@ -730,3 +730,33 @@ begin
|
|||||||
else
|
else
|
||||||
Result := E_NOTIMPL;
|
Result := E_NOTIMPL;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ Delta stream support }
|
||||||
|
|
||||||
|
|
||||||
|
procedure TComponent.GetDeltaStreams(aProc: TGetStreamProc);
|
||||||
|
|
||||||
|
begin
|
||||||
|
// To be implemented by descendants
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TComponent.ReadDeltaStream(const S: TStream);
|
||||||
|
begin
|
||||||
|
S.ReadComponent(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TComponent.ReadDeltaState;
|
||||||
|
|
||||||
|
var
|
||||||
|
Done : boolean;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if (csDesigning in ComponentState) then
|
||||||
|
exit;
|
||||||
|
Done:=False;
|
||||||
|
if Assigned(FOnGetDeltaStreams) then
|
||||||
|
FOnGetDeltaStreams(Self,@ReadDeltaStream,Done);
|
||||||
|
if not Done then
|
||||||
|
GetDeltaStreams(@ReadDeltaStream);
|
||||||
|
end;
|
||||||
|
|
||||||
|
@ -1889,6 +1889,35 @@ begin
|
|||||||
raise EClassNotFound.CreateFmt(SNoFieldOfClassIn, [AClassName, Root.ClassName]);
|
raise EClassNotFound.CreateFmt(SNoFieldOfClassIn, [AClassName, Root.ClassName]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TReader.ReadComponentDeltaRes(Instance: TComponent; const DeltaCandidates: array of Ansistring; const Proc: TGetStreamProc): TComponent;
|
||||||
|
|
||||||
|
var
|
||||||
|
ResHandle: THandle;
|
||||||
|
RootName, Delta, DeltaName: AnsiString;
|
||||||
|
S: TStream;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if (Instance=nil) or not Assigned(Proc) then
|
||||||
|
Raise EArgumentNilException.Create(SArgumentNil);
|
||||||
|
Result:=Instance;
|
||||||
|
RootName:=Instance.ClassName;
|
||||||
|
for Delta in DeltaCandidates do
|
||||||
|
begin
|
||||||
|
DeltaName:=RootName+'_'+Delta;
|
||||||
|
// No module support yet
|
||||||
|
ResHandle:=FindResource(Nilhandle,PAnsiChar(DeltaName), PAnsiChar(RT_RCDATA));
|
||||||
|
if ResHandle<>NilHandle then
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
if ResHandle=NilHandle then
|
||||||
|
exit;
|
||||||
|
S:=TResourceStream.Create(NilHandle,DeltaName, PChar(RT_RCDATA));
|
||||||
|
try
|
||||||
|
Proc(S);
|
||||||
|
finally
|
||||||
|
S.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TAbstractObjectReader }
|
{ TAbstractObjectReader }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user