Jump to content
Ian Branch

Change of coding style/structure..

Recommended Posts

13 hours ago, Ian Branch said:

Or perhaps..


    MyDialog := TTaskDialog.Create(Self);
    MyDialog.Title := 'Warning!';
    MyDialog.Text := 'Relevant/selected Records prior to ' + sArchivedDate + ' have been Archived!' + #13 + 'This may make the figures inaccurate!';
    MyDialog.CommonButtons := [tcbOk];
    try
      MyDialog.Execute;
    finally
      MyDialog.Free;
    end;

 

This blows my mind. The try/finally is to protect the resource. So you must enter the try immediately after the resource has been acquired. 

 

I suggest that you read Dalija's book on memory management. 

  • Like 2

Share this post


Link to post
22 hours ago, Sherlock said:

Nonono, of course not. I just wanted to weaken the "it's just another tool in the box" argument.

Goto is an another tool in the box as well 😉 Mainly for highly-optimized routines though (FastCode's functions are full of them).

However I never needed it myself in my code

Edited by Fr0sT.Brutal

Share this post


Link to post
On 10/11/2022 at 6:23 PM, Ian Branch said:

The passion behind not using 'with' is interesting.

Also interesting is that I see no advocates.  Yes, yes, you will say "And the reason is....". 🙂

To me it is just another tool in the tool box of the language.

I can see and understand where concerns may be but as with any tool, used correctly, there is no issue.

When I was using With a lot, I had the same view about With. But as it was already mentioned, a big disadvantage is using debugger with such a code. Very cumbersome, so I removed all With usage, except for a few basic forms, as in your example, for simple ShowModal - and these are in the process to be removed from using With, too!

 

Do you use Virtual Treeview (TVirtualStringTree), have you ever looked into the code or try to figure it out? The usage of With is in every other method, including nested With!

Such a great component, so incompatible with debugger!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×