Jump to content

[Tips] Using AutoCompletion For Easy Remember Variable Names

- - - - -

  • Please log in to reply
No replies to this topic

#1
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts
Unlike many other programmer, I found my memory is not good enough to remember all the small details like the names of variable declared in other units. My trick to overcome this is to declare a record containing all the variables and make a global variable for that record, and name that variable something that's very easy to remember. Like Global? :P. This way we can take full advantage of Delphi AutoCompletion feature. Whenever we need to refer to a global variable we only have to type Global followed by dot (.) and then list of known global variables will pop up (Ctrl+Space if the list does not show up).

For example, let's say that you need to have 3 global variables:
  • LoginTime: TDateTime;
  • FileName : string;
  • Total : Currency;

Now let's collect them inside a record like:


type

  TGlobalVars=record

    LoginTime: TDateTime;

    FileName : string;

    Total    : Currency;

  end;


And declare a global variable of type TGlobalVars, like this:

var

  Global: TGlobalVars;


Now everytime we want to use one of the "real" global variable, we don't have to remember the exact name. Just type Global. and Delphi AutoCompletion will present you with the list like shown below.

[ATTACH]3612[/ATTACH]

I found this trick really saves me a lot of time from the necessity to open and close units just to check for variable names (is it UsrPassword, [I]UserPwd
, or [I]UsrPass
? for an example, :c-lol:).

Attached Files






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users