persist.inc 3.5 KB

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