Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-05

Setting String Properties of Custom Component = AV

11 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Lee Jenkins

Hi all, I have a custom component that I've created and I get an AV anytime I try to change/set a string property within the IDE. Setting these properties at runtime doesn't produce the AV.

Also, the message that I get is simply "Access Violation". No more information other than that.

I'm using Lazarus 0.9.24.

Thanks,

Warm Regards, Lee

Reply by email

Lee Jenkins
to Lee Jenkins
Lee Jenkins wrote 11 lines
Hi all, I have a custom component that I've created and I get an AV anytime I try to change/set a string property within the IDE. Setting these properties at runtime doesn't produce the AV. Also, the message that I get is simply "Access Violation". No more information other than that. I'm using Lazarus 0.9.24. Thanks,

Also, I'm having another problem with this component. It's a TShape descendant and I have hooked up mousedown and mouseup events to change Pen.color and Brush.Color properties to different values in order to indicate visual feedback.

If I create the component at runtime, the values work. IE: If I mouse down on the component the colors changes as expected. If I create the component at design time, then there is no change.

I suspect there are some subtle difference in streaming or something between the way Delphi does it and Lazarus, but am at a loss as to what those could be.

Thanks again,

Warm Regards, Lee

Reply by email

Lee Jenkins
to Lee Jenkins
Lee Jenkins wrote 26 lines
Lee Jenkins wrote: > Hi all, I have a custom component that I've created and I get an AV anytime I > try to change/set a string property within the IDE. Setting these properties at > runtime doesn't produce the AV. > > Also, the message that I get is simply "Access Violation". No more information > other than that. > > I'm using Lazarus 0.9.24. > > Thanks, > Also, I'm having another problem with this component. It's a TShape descendant and I have hooked up mousedown and mouseup events to change Pen.color and Brush.Color properties to different values in order to indicate visual feedback. If I create the component at runtime, the values work. IE: If I mouse down on the component the colors changes as expected. If I create the component at design time, then there is no change. I suspect there are some subtle difference in streaming or something between the way Delphi does it and Lazarus, but am at a loss as to what those could be. Thanks again,

Setting Mode to Delphi fixed it, but I'm curious as to how to get this to work in FPC mode.

Thanks,

Warm Regards, Lee

Reply by email

Mattias Gaertner
to Lee Jenkins: Hi all, I have a custom component that I've created and I get an AV anytime I try to…
Show quoted text 9 lines
Hi all, I have a custom component that I've created and I get an AV anytime I try to change/set a string property within the IDE. Setting these properties at runtime doesn't produce the AV. Also, the message that I get is simply "Access Violation". No more information other than that. I'm using Lazarus 0.9.24.

Start the IDE with gdb and create a breaktrace.

http://wiki.lazarus.freepascal.org/Creating_a_Backtrace_with_GDB

Mattias

Reply by email

Mattias Gaertner
to Lee Jenkins: Setting Mode to Delphi fixed it, but I'm curious as to how to get this to work in FPC…
Show quoted text 18 lines
Lee Jenkins wrote: > Lee Jenkins wrote: >> Hi all, I have a custom component that I've created and I get an >> AV anytime I try to change/set a string property within the IDE. >> Setting these properties at runtime doesn't produce the AV. >> >> Also, the message that I get is simply "Access Violation". No >> more information other than that. >> >> I'm using Lazarus 0.9.24. >> >> Thanks, >> > > Also, I'm having another problem with this component. It's a > TShape descendant and I have hooked up mousedown and mouseup events > to change Pen.color and Brush.Color properties to different values > in order to indicate visual feedback.

MousDown and MouseUp events are handled by the IDE (designer).

Show quoted text 13 lines
> If I create the component at runtime, the values work. IE: If I > mouse down on the component the colors changes as expected. If I > create the component at design time, then there is no change. > > I suspect there are some subtle difference in streaming or > something between the way Delphi does it and Lazarus, but am at a > loss as to what those could be. > > Thanks again, > Setting Mode to Delphi fixed it, but I'm curious as to how to get this to work in FPC mode.

Maybe this helps:
http://www.freepascal.org/docs-html/prog/progap4.html#progse62.html

Mattias

Reply by email

Lee Jenkins
to Mattias Gaertner
Mattias Gaertner wrote 24 lines
On Thu, 01 May 2008 14:31:13 -0400 Lee Jenkins wrote: > Lee Jenkins wrote: >> Lee Jenkins wrote: >>> Hi all, I have a custom component that I've created and I get an >>> AV anytime I try to change/set a string property within the IDE. >>> Setting these properties at runtime doesn't produce the AV. >>> >>> Also, the message that I get is simply "Access Violation". No >>> more information other than that. >>> >>> I'm using Lazarus 0.9.24. >>> >>> Thanks, >>> >> Also, I'm having another problem with this component. It's a >> TShape descendant and I have hooked up mousedown and mouseup events >> to change Pen.color and Brush.Color properties to different values >> in order to indicate visual feedback. MousDown and MouseUp events are handled by the IDE (designer).

Sorry Mattias, I wasn't clear enough. When I site the component at *design time*, the mouse down events do not fire at *runtime*. In the create event, I have this:

constructor TPOSButton.Create(AOwner: TComponent);
begin
   inherited Create(AOwner);
   Self.OnMouseDown := HandleMouseDown;  // <== handlers with correct signatures.
   self.OnMouseUp := HandleMouseUp;
end;
Show quoted text 16 lines
>> If I create the component at runtime, the values work. IE: If I >> mouse down on the component the colors changes as expected. If I >> create the component at design time, then there is no change. >> >> I suspect there are some subtle difference in streaming or >> something between the way Delphi does it and Lazarus, but am at a >> loss as to what those could be. >> >> Thanks again, >> > Setting Mode to Delphi fixed it, but I'm curious as to how to get > this to work in FPC mode. Maybe this helps: http://www.freepascal.org/docs-html/prog/progap4.html#progse62.html

I'll take a look. Thank you.

Warm Regards, Lee

Reply by email

Funky Beast
to Lee Jenkins
Lee Jenkins wrote 21 lines
>>> Also, I'm having another problem with this component. It's a >>> TShape descendant and I have hooked up mousedown and mouseup events >>> to change Pen.color and Brush.Color properties to different values >>> in order to indicate visual feedback. > MousDown and MouseUp events are handled by the IDE (designer). > > Sorry Mattias, I wasn't clear enough. When I site the component at *design time*, the mouse down events do not fire at *runtime*. In the create event, I have this: constructor TPOSButton.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.OnMouseDown := HandleMouseDown; // <== handlers with correct signatures. self.OnMouseUp := HandleMouseUp; end; >> Setting Mode to Delphi fixed it, but I'm curious as to how to get >> this to work in FPC mode.

Hi,

In FPC mode, your event assignments should prefix with '@' like this:

constructor TPOSButton.Create(AOwner: TComponent);
begin
   inherited Create(AOwner);
   Self.OnMouseDown := @HandleMouseDown;  // <== handlers with correct signatures.
   self.OnMouseUp := @HandleMouseUp;
end;

HTH,
Funky Beast

Reply by email

Lee Jenkins
to Funky Beast
Funky Beast wrote 34 lines
Lee Jenkins wrote: >>>> Also, I'm having another problem with this component. It's a >>>> TShape descendant and I have hooked up mousedown and mouseup events >>>> to change Pen.color and Brush.Color properties to different values >>>> in order to indicate visual feedback. >> MousDown and MouseUp events are handled by the IDE (designer). >> >> > Sorry Mattias, I wasn't clear enough. When I site the component at *design > time*, the mouse down events do not fire at *runtime*. In the create event, I > have this: > > constructor TPOSButton.Create(AOwner: TComponent); > begin > inherited Create(AOwner); > Self.OnMouseDown := HandleMouseDown; // <== handlers with correct signatures. > self.OnMouseUp := HandleMouseUp; > end; > >>> Setting Mode to Delphi fixed it, but I'm curious as to how to get >>> this to work in FPC mode. Hi, In FPC mode, your event assignments should prefix with '@' like this: constructor TPOSButton.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.OnMouseDown := @HandleMouseDown; // <== handlers with correct signatures. self.OnMouseUp := @HandleMouseUp; end; HTH, Funky Beast

They were, but I had to change the mode to Delphi to get the String properties from throwing an AV when I tried to set them at design time.

Thanks,

Warm Regards, Lee

Reply by email

Mattias Gaertner
to Lee Jenkins
Show quoted text 21 lines
[...] >>>> Setting Mode to Delphi fixed it, but I'm curious as to how to get >>>> this to work in FPC mode. > Hi, > > In FPC mode, your event assignments should prefix with '@' like > this: > > constructor TPOSButton.Create(AOwner: TComponent); > begin > inherited Create(AOwner); > Self.OnMouseDown := @HandleMouseDown; // <== handlers with > correct signatures. self.OnMouseUp := @HandleMouseUp; > end; > > HTH, > Funky Beast They were, but I had to change the mode to Delphi to get the String properties from throwing an AV when I tried to set them at design time.

Then you forgot the {$H+} switch to enable ansistrings.

Every lazarus unit begins with:
{$mode ObjFPC}{$H+}

Mattias

Reply by email

Mattias Gaertner
to Lee Jenkins: Sorry Mattias, I wasn't clear enough. When I site the component at *design time*, the…
Show quoted text 11 lines
[...] Sorry Mattias, I wasn't clear enough. When I site the component at *design time*, the mouse down events do not fire at *runtime*. In the create event, I have this: constructor TPOSButton.Create(AOwner: TComponent); begin inherited Create(AOwner); Self.OnMouseDown := HandleMouseDown; // <== handlers with correct signatures. self.OnMouseUp := HandleMouseUp; end;

Components should not set their own events, but instead override the methods. For example

  protected
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,
           Y: Integer); override;
procedure TPOSButton.MouseDown(Button: TMouseButton; Shift:
TShiftState; X, Y: Integer);
begin
  inherited MouseDown(Button, Shift, X, Y);
end;

Mattias

Reply by email

Lee Jenkins
to Mattias Gaertner
Mattias Gaertner wrote 30 lines
On Thu, 01 May 2008 19:57:33 -0400 Lee Jenkins wrote: > [...] > Sorry Mattias, I wasn't clear enough. When I site the component at > *design time*, the mouse down events do not fire at *runtime*. In > the create event, I have this: > > constructor TPOSButton.Create(AOwner: TComponent); > begin > inherited Create(AOwner); > Self.OnMouseDown := HandleMouseDown; // <== handlers with correct > signatures. self.OnMouseUp := HandleMouseUp; > end; Components should not set their own events, but instead override the methods. For example protected procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure TPOSButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin inherited MouseDown(Button, Shift, X, Y); end; Mattias

That was it, Mattias. Thank you, I am learning quite a bit about component writing which is a new endeavor for me.

I have just one more problem with this component which is centering the text vertically. I had posted a separate thread above concerning this and once I figure out how to get the text to center vertically, I should this component right where I want it :)

Thanks again, everyone's help is most appreciated.

Warm Regards, Lee "When my company started out, we were really, really, really, really small. Now...we're just really small."

Reply by email