[Lazarus] Newbie: Greeting and ask how to add a patch?

Leslie Kaye les.kaye at couchmansfarm.plus.com
Wed Jul 29 15:33:03 CEST 2009


Christian Iversen wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">On 
> 2009-07-28 12:08, Raditya Perdhevi wrote:
>> hi all,
>> i don't know if this is the right place to ask but i have a stupid 
>> question
>> how can i add a patch?
>
> It certainly is! Although I'm not involved enough with the project to 
> be totally sure, unfortunately :)
Patches are created and applied with a subversion client
http://en.wikipedia.org/wiki/Comparison_of_Subversion_clients
Also see the Lazarus wiki about getting the latest SVN trunc Lazarus code
If you want to submit a patch then create a bug report about the issue 
and upload your patch file to the bug report. If it is a good patch then 
one of the project managers will apply it to the product.
Actually I think it should be compulsory to submit a patch with bug 
reports - maybe more would get resolved!!
>
>> some time ago i've added a small adjustment on RX component from
>> Lazarus-CCR, to be exactly, i've added this lines on rxlookup.pas
>> on OnClosePopup method in TRxCustomDBLookupEdit class
>>
>>    if assigned(FRxPopUpForm) then
>>    begin
>>      FRxPopUpForm := nil;
>>    end;
>
> This just seems superfluous. Isn't the FRxPopUpForm just a straight 
> variable? Then just assign nil to it. There should be no need to check 
> it for non-nility when you're just going to nil it anyway.
>
I worry about this code. Does the FRxPopUpForm get freed elsewhere?  
Without garbage collection you need to be wary of memory leaks.

I have not looked at the source you are working on so forgive me if the 
following comment is not applicable. It may in any case be a good tip 
for others on the mailing list.

To trash FRxPopUpForm  you could

FRxPopUpForm.Free;
FRxPopUpForm := nil;

Free checks for nil so you do not get an access violation even if it is 
already nil

Application forms should be created with the Application.CreateForm 
method so they get added to the Application's Forms list, to be drawn in 
the correct order and honour any fsStayOnTop settings. It should be left 
to the application to clean them up on exit.

Component related forms (as I think is the case that you are talking 
about)  (or any other component you need to point to - not just forms) 
which are pointed to by a component field (F variable) (rather than by a 
local (method) variable) should best use the TComponent Notification 
procedure to nil the field if the form can be destroyed at run time 
before the component is destroyed

If you are creating the form in your component ...

FRxPopUpForm.Create(  {Self, nil or whatever});
FRxPopUpForm.FreeNotification(Self)


Otherwise if the RxPopUpForm already exists external to your component 
and you want to know if it gets destroyed ...

Declare a property in your component...

property RxPopUpForm : TRxPopUpForm read FRxPopUpForm write SetRxPopUpForm;

then implement the property setter

procedure TMyComponent.SetRxPopUpForm(Value: TRxPopUpForm );
begin
  if  (Value = FRxPopUpForm) then
    Exit;
  if Assigned(FRxPopUpForm) then
    FRxPopUpForm.RemoveFreeNotification(Self);
  FRxPopUpForm := Value;
  if Assigned(FRxPopUpForm) then
    FRxPopUpForm.FreeNotification(Self);
end  

Either way you write a notification override procedure to nil the property.

procedure TMyComponent.Notification(AComponent: TComponent; Operation: 
TOperation);
begin
  inherited Notification(AComponent, Operation);
  case Operation of
  opRemove:
    if   (AComponent =  FRxPopUpForm) then
      FRxPopUpForm := nil;
  end; // case
end  

in this way you can free the FRxPopUpForm instance anywhere at any time 
and your component will know that it is now nil.


if you are creating and destroying FRxPopUpForm  inside a method you 
just protect the code with a try .. finally block to make sure that you 
clean up the memory allocation.

Hope this is of help to somebody!













More information about the Lazarus mailing list