Delphi: Check whether object or variable exists
Tip by Delphian | 2013-02-15 at 12:51
Sometimes you have to test whether an object or variable in Delphi exists at all or has already been initialized. How you do it, I show you in this tip.
We are using assigned() for this purpose. Assigned() returns true, if the object is existing and false if not. Let's look at an example:
var sl: TStringList; ... if assigned(sl) then sl.free; ... if assigned(sl)=false then sl:=TStringList.Create();
In this example, we only free the StringList in the case, the StringList exists and we are creating a new StringList only in the case, the StringList is not existing.
About the Author
The author has not added a profile short description yet.
Show Profile
Related Topics
SQLite: Check whether Table exists
Info | 0 Comments
Delphi/Lazarus: Is the ALT, SHIFT or CTRL key pressed?
Tutorial | 0 Comments
jQuery: Does an Element exist?
Tip | 1 Comment
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
Lazarus: Load File as Byte Array and save Byte Array as File
Tutorial | 0 Comments
Delphi: Multiline Caption for TLabel (at Run Time and Design Time)
Tutorial | 1 Comment
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.