persist.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. {
  2. This file is part of the Free Component Library (FCL)
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {****************************************************************************}
  11. {* TPersistent *}
  12. {****************************************************************************}
  13. procedure TPersistent.AssignError(Source: TPersistent);
  14. Var SourceName : String;
  15. begin
  16. If Source<>Nil then
  17. SourceName:=Source.ClassName
  18. else
  19. SourceName:='Nil';
  20. Writeln ('Error assigning to ',ClassName,' from : ',SourceName);
  21. raise EConvertError.CreateFmt (SAssignError,[SourceName,ClassName]);
  22. end;
  23. procedure TPersistent.AssignTo(Dest: TPersistent);
  24. begin
  25. Dest.AssignError(Self);
  26. end;
  27. procedure TPersistent.DefineProperties(Filer: TFiler);
  28. begin
  29. end;
  30. function TPersistent.GetOwner: TPersistent;
  31. begin
  32. Result:=Nil;
  33. end;
  34. destructor TPersistent.Destroy;
  35. begin
  36. Inherited Destroy;
  37. end;
  38. procedure TPersistent.Assign(Source: TPersistent);
  39. begin
  40. If Source<>Nil then
  41. Source.AssignTo(Self)
  42. else
  43. AssignError(Nil);
  44. end;
  45. function TPersistent.GetNamePath: string;
  46. Var OwnerName :String;
  47. begin
  48. Result:=ClassNAme;
  49. If GetOwner<>Nil then
  50. begin
  51. OwnerName:=GetOwner.GetNamePath;
  52. If OwnerName<>'' then Result:=OwnerName+'.'+Result;
  53. end;
  54. end;
  55. {****************************************************************************}
  56. {* TInterfacedPersistent *}
  57. {****************************************************************************}
  58. procedure TInterfacedPersistent.AfterConstruction;
  59. begin
  60. inherited;
  61. // if GetOwner<>nil then
  62. // GetOwner.GetInterface(IUnknown,FOwnerInterface);
  63. end;
  64. function TInterfacedPersistent._AddRef: Integer;stdcall;
  65. begin
  66. if FOwnerInterface<>nil then
  67. Result:=FOwnerInterface._AddRef
  68. else
  69. Result:=-1;
  70. end;
  71. function TInterfacedPersistent._Release: Integer;stdcall;
  72. begin
  73. if FOwnerInterface <> nil then
  74. Result:=FOwnerInterface._Release
  75. else
  76. Result:=-1;
  77. end;
  78. function TInterfacedPersistent.QueryInterface(const IID: TGUID; out Obj): HResult;stdcall;
  79. begin
  80. if GetInterface(IID, Obj) then
  81. Result:=0
  82. else
  83. Result:=HResult($80004002);
  84. end;
  85. {****************************************************************************}
  86. {* TRecall *}
  87. {****************************************************************************}
  88. constructor TRecall.Create(AStorage,AReference: TPersistent);
  89. begin
  90. inherited Create;
  91. FStorage:=AStorage;
  92. FReference:=AReference;
  93. Store;
  94. end;
  95. destructor TRecall.Destroy;
  96. begin
  97. if Assigned(FReference) then
  98. FReference.Assign(FStorage);
  99. Forget;
  100. inherited;
  101. end;
  102. procedure TRecall.Forget;
  103. begin
  104. FReference:=nil;
  105. FreeAndNil(FStorage);
  106. end;
  107. procedure TRecall.Store;
  108. begin
  109. if Assigned(FReference) then
  110. FStorage.Assign(FReference);
  111. end;