Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Vor SetPropValue auf ReadOnly testen (https://www.delphipraxis.net/151667-vor-setpropvalue-auf-readonly-testen.html)

SarDGer 27. Mai 2010 12:19


Vor SetPropValue auf ReadOnly testen
 
Moin Moin,

ich hab da ein kleines Problem...
Ich will die Properties eines Objects in die
Properties eines anderen Objects kopieren.

Delphi-Quellcode:
function CopyPropValues(aSourceObj, aDestinationObject : TPersistent): Boolean;
var
  I        : Integer;
  propCount : Integer;
  PropInfo : PPropInfo;
  PropList : PPropList;
begin
  propCount := GetPropList(aSourceObj, PropList);
  for I := 0 to propCount - 1 do
  begin
    PropInfo := PropList^[I];

    case PropInfo^.PropType^.Kind of
      tkClass : SetObjectProp(aDestinationObject, PropInfo.Name, GetObjectProp(aSourceObj, PropInfo.Name));
      tkMethod : SetMethodProp(aDestinationObject, PropInfo.Name, GetMethodProp(aSourceObj, PropInfo.Name));
      else
        SetPropValue(aDestinationObject, PropInfo.Name, GetPropValue(aSourceObj, PropInfo.Name));
    end;
  end;

  FreeMem(PropList);
end;
Soweit so lustig. Allerdings haut es sich weg wenn die Property ReadOnly ist.
Was ja nachvollziebar ist. Aber wie prüfe ich vor dem Set nach ob die aktuelle
Prop nu readOnly ist oder nicht.

Vielen dank im voraus.
Sar D'Ger

Neutral General 27. Mai 2010 12:22

Re: Vor SetPropValue auf ReadOnly testen
 
Hallo,

Ich bin mir nicht sicher, aber vllt hilft:

Delphi-Quellcode:
if Assigned(PropInfo^.SetProc) then
  SetPropValue(...);
?

Edit: Habs getestet und so geht es bei mir :wink:

SarDGer 27. Mai 2010 12:36

Re: Vor SetPropValue auf ReadOnly testen
 
Hab's auch getested und bei mir sieht's auch gut aus :-D

SetProc und GetProc beziehen sich offenscheinlich auf die
Getter bzw Setter Routine. Oh mann, hätte ich auch selber
drauf kommen können, aber manchmal ist man wie vernagelt.

Vielen Dank für die schnelle Antwort,
Sar D'Ger


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:55 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz