Sign in Join

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

Mailing lists / lazarus / 2008-12

Had a ..

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Samuel Herzog

Hi folks,
I had some minutes of sparetime and went through control.inc.

Two things I d' like to ask:

1.) sometimes "parent"/"FParent" are checked for nil, before the method access it, and sometime not. Is this by purpose or are this potential Access-Violation candidates.

2.) In my programming-style I often check the conditions of input parameters at the begin of the method and leave with "exit"-statement if the conditions do not match the current needs.

As for example like here:
procedure TControl.ParentFontChanged;
begin
  if csLoading in ComponentState then exit;

Such things make the code much better readable.

I also use this in situations like this:

procedure TControl.SetColor(value : TColor);
begin
  if FColor  Value then
  begin
    FColor := Value;
    FParentColor := False;
    Invalidate;
  end;
end;
There is no need for begin/end-statement.
if FColor=Value then exit;

Are there any rules for lazarus in this case or can everyone handle this as he likes ?

Greets,

Sam

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20081214/e94799c4/attachment.html

Reply by email

Mattias Gaertner
to Samuel Herzog
Show quoted text 8 lines
Hi folks, I had some minutes of sparetime and went through control.inc. Two things I d' like to ask: 1.) sometimes "parent"/"FParent" are checked for nil, before the method access it, and sometime not. Is this by purpose or are this potential Access-Violation candidates.

For example?

Show quoted text 27 lines
2.) In my programming-style I often check the conditions of input parameters at the begin of the method and leave with "exit"-statement if the conditions do not match the current needs. As for example like here: procedure TControl.ParentFontChanged; begin if csLoading in ComponentState then exit; Such things make the code much better readable. I also use this in situations like this: procedure TControl.SetColor(value : TColor); begin if FColor Value then begin FColor := Value; FParentColor := False; Invalidate; end; end; There is no need for begin/end-statement. if FColor=Value then exit; Are there any rules for lazarus in this case or can everyone handle this as he likes ?

Some people consider 'exit', break' and 'continue' as harder to read. IMO it is a matter of taste and both are equally readable, so both should be allowed.

see
http://wiki.lazarus.freepascal.org/DesignGuidelines

Mattias

Reply by email

Samuel Herzog
to Mattias Gaertner

For example:

procedure TControl.ParentFontChanged;
begin
  if csLoading in ComponentState then exit;
  if FParentFont then
  begin
    Font := FParent.Font;
    FParentFont := true;
  end;
end;

or

procedure TControl.AnchorAsAlign(TheAlign: TAlign; Space: Integer);
begin
  Parent.DisableAlign;
  try

or

procedure TControl.CMParentColorChanged(var Message: TLMessage);
begin
  if csLoading in ComponentState then exit;
  if FParentColor then
  begin
    Color := FParent.Color;
    FParentColor := true;
  end;

or

procedure TControl.CMParentShowHintChanged(var Message: TLMessage);
begin
  if FParentShowHint then
  begin
    ShowHint := FParent.ShowHint;
    FParentShowHint := true;
  end;
end;

________________________________
Von: Mattias Gaertner
An:
Gesendet: Sonntag, den 14. Dezember 2008, 17:29:12 Uhr Betreff: Re: [Lazarus] Had a ..

Show quoted text 8 lines
Hi folks, I had some minutes of sparetime and went through control.inc. Two things I d' like to ask: 1.) sometimes "parent"/"FParent" are checked for nil, before the method access it, and sometime not. Is this by purpose or are this potential Access-Violation candidates.

For example?

Show quoted text 27 lines
2.) In my programming-style I often check the conditions of input parameters at the begin of the method and leave with "exit"-statement if the conditions do not match the current needs. As for example like here: procedure TControl.ParentFontChanged; begin if csLoading in ComponentState then exit; Such things make the code much better readable. I also use this in situations like this: procedure TControl.SetColor(value : TColor); begin if FColor Value then begin FColor := Value; FParentColor := False; Invalidate; end; end; There is no need for begin/end-statement. if FColor=Value then exit; Are there any rules for lazarus in this case or can everyone handle this as he likes ?

Some people consider 'exit', break' and 'continue' as harder to read. IMO it is a matter of taste and both are equally readable, so both should be allowed.

see
http://wiki.lazarus.freepascal.org/DesignGuidelines

Mattias

Reply by email

Mattias Gaertner
to Samuel Herzog
Show quoted text 12 lines
For example: procedure TControl.ParentFontChanged; begin if csLoading in ComponentState then exit; if FParentFont then begin Font := FParent.Font; FParentFont := true; end; end;

Called by parent, so Parentnil.

Show quoted text 6 lines
or procedure TControl.AnchorAsAlign(TheAlign: TAlign; Space: Integer); begin Parent.DisableAlign; try

If Parent=nil then user made an error.

Show quoted text 11 lines
or procedure TControl.CMParentColorChanged(var Message: TLMessage); begin if csLoading in ComponentState then exit; if FParentColor then begin Color := FParent.Color; FParentColor := true; end;

Called by parent, so Parentnil.

Show quoted text 10 lines
or procedure TControl.CMParentShowHintChanged(var Message: TLMessage); begin if FParentShowHint then begin ShowHint := FParent.ShowHint; FParentShowHint := true; end; end;

Called by parent, so Parentnil.

Mattias

Reply by email