Ran into something that I don't think I'm doing correctly. I think I'm not good with this code, I got part of it working then now crashing the IDE when installing the component. I backed out most all of the code except the declarations and publishing, then took out publishing the new props and hard crash on the IDE. I figure it was the array code. What is ODD is that with the array of TDTBandsSettings that seems to work OK as is showing below, but when adding the TDTTextSettings and related Bitmap, it blows up hard when restarting the IDE on a test project with the component. Just want to make sure the way I'm dealing with arrays is that the objects are just references and it's OK to assign and deal with the way I did it.
Being lazy and wanting to move ahead with a component I'm working on I needed a few of the same item for setting properties. These are things that are derived from TPersistant so I can see them in the Object Inspector. I see examples of using TCollection and creating an editor but for now not going to do that as it's a bit more work than I can do.
So I just created individual properties for each one (I hate this, but at least can keep me moving).
I have some declarations in my class and related helpers, cons dtors like this -
(Question below the code block)
...
TDTCustomThemedGauge = class(TGraphicControl)
private
{ Private declarations }
FDirty: boolean;
...
// Bands
FBandsSettings: array[0..3] of TDTBandSettings;
FTextsSettings: array[0..2] of TDTTextSettings;
// bitmaps
FTextsBitmaps: array[0..2] of TBGRABitmap;
...
// these get published
property TextSettings1: TDTTextSettings read FTextsSettings[0] write SetTextSettings1;
property TextSettings2: TDTTextSettings read FTextsSettings[1] write SetTextSettings2;
property TextSettings3: TDTTextSettings read FTextsSettings[2] write SetTextSettings3;
property FrameSettings: TDTFrameSettings read FFrameSettings write SetFrameSettings;
property ScaleSettings: TDTScaleSettings read FScaleSettings write SetScaleSettings;
property BandSettings1: TDTBandSettings read FBandsSettings[0] write SetBandSettings1;
property BandSettings2: TDTBandSettings read FBandsSettings[1] write SetBandSettings2;
property BandSettings3: TDTBandSettings read FBandsSettings[2] write SetBandSettings3;
property BandSettings4: TDTBandSettings read FBandsSettings[3] write SetBandSettings4;
...
implementation
constructor TDTCustomThemedGauge.Create(AOwner: TComponent);
var
i: integer;
begin
inherited Create(AOwner);
for i := low(FBandsSettings) to high(FBandsSettings) do
begin
FBandsSettings[i] := TDTBandSettings.Create;
FBandsSettings[i].OnChange := DoChange;
end;
for i := low(FTextsSettings) to high(FTextsSettings) do
begin
FTextsSettings[i] := TDTTextSettings.Create;
FTextsSettings[i].OnChange := DoChange;
FTextsBitmaps[i] := TBGRABitmap.Create;
end;
...
end;
destructor TDTCustomThemedGauge.Destroy;
var
i: integer;
begin
for i := low(FTextsSettings) to high(FTextsSettings) do
begin
FTextsSettings[i].OnChange := nil;
FTextsSettings[i].FontEx.OnChange := nil;
FTextsSettings[i].Free;
FTextsBitmaps[i].Free;
end;
for i := low(FBandsSettings) to high(FBandsSettings) do
begin
FBandsSettings[i].OnChange := nil;
FBandsSettings[i].Free;
end;
...
inherited Destroy;
end;
procedure TDTCustomThemedGauge.SetTextSettings1(AValue: TDTTextSettings);
begin
if FTextsSettings[0] = AValue then // may not make sense for an object, but wtf
Exit;
FTextsSettings[0] := AValue;
FTextsSettings[0].Dirty := True; // set it, as it will need a repaint
FAnyTextDirty := True;
DoChange(self);
end;
...
procedure TDTCustomThemedGauge.SetBandSettings1(AValue: TDTBandSettings);
begin
if FBandsSettings[0] = AValue then
Exit;
FBandsSettings[0] := AValue;
FBandsSettings[0].Dirty := True;
FAnyBandDirty:= true;
DoChange(self);
end;
...
So the question is do these variable declarations instantiate the objects or just create an array of references like I want?
I ran into a situation where I have an IDE crashing bug that I can't quite find and presume it's related to the changes to using an array vs. a single value. Rest of the code was modified to use array indexes as needed. I have rebuilt all related code in the BGRA Libs which this is part of just to make sure. And anything else to make sure it's not a build issue.
Image is of the Object Inspector with it working when ONLY the TDTBandSettings are created, everything seems to work fine, but I'm very suspicious of a False positive.
Lastly any limitations on the number of properties a component can have. A
long long time ago Delphi had some small limit as I recall, but any limits of counts properties for a component?
Rolling back code, and going to do it one step at a time, but any advice on the hack job of code to get multiple-props going would be helpful.
Thanks
Sandy