Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Check if instance exist? (https://www.delphipraxis.net/102448-check-if-instance-exist.html)

FaNIX 29. Okt 2007 07:37


Check if instance exist?
 
Hi,

In delphi, how do i check if a instance of a class has already been created or not?

Something like this in VB:

Delphi-Quellcode:
        If (FtpClient Is Nothing) Then
            Return
        End If
I want to check if the Fo_FtpClient has already been created or not: Here is my code:

Delphi-Quellcode:
unit u_fdn_FTP_Dot_Net;

interface

uses
    System.Net,
    System.Net.Sockets,
    System.Text,
    System.IO,
    Borland.Vcl.Classes,
    Borland.Vcl.StrUtils,
    Borland.Vcl.SysUtils,
    Borland.Vcl.Dialogs,
    TKFP.IO,
    TKFP.Net;

type
    TFtp_Dot_Net = class(TObject)
    private
        [b]Fo_FtpClient : TKFP.Net.FtpClient;[/b]
Then before creating it again in the onclick event, i first want to check if it doesnt already exist:

Delphi-Quellcode:
Fo_FtpClient := FtpClient.Create(oLogon,Address,21);

SubData 29. Okt 2007 07:41

Re: Check if instance exist?
 
hi

Delphi-Quellcode:
if not Assigned(Class) then
  Class.Create(Param):
Assigned tests if the function is nil or not.
hope this helpts.

FaNIX 29. Okt 2007 07:44

Re: Check if instance exist?
 
Zitat:

Zitat von SubData
hi

Delphi-Quellcode:
if not Assigned(Class) then
  Class.Create(Param):
Assigned tests if the function is nil or not.
hope this helpts.

Thnx, works 100% :)

DP-Maintenance 29. Okt 2007 08:20

DP-Maintenance
 
Dieses Thema wurde von "Matze" von "Programmieren allgemein" nach "Object-Pascal / Delphi-Language" verschoben.
Delphi question


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:44 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz