How to remove the main form or how to create an object in console app?

[b][red]This message was edited by bogdanul2003 at 2004-5-9 1:25:36[/red][/b][hr]
is it possibel to make an delphi appl wich first has a form and then remove the form.I want to do this becouse my application doesn't need a main form(the exe file of a simple appl whith only one form ocupies about 351 kb).If i remove the main form i'll still need to be abel to use unit's like IdComponent,IdTCPConnection,IdTCPClient,tlhelp32,psapi, ScktComp
Can this be done ?

If not the pls tell me how to cteate a new component in a console application.For eg:ClientSocket1:TClientSocket;
ClientSocket1.create();
What must the create() param because when i try ClientSocket1.create(self); it passes this error:[Error] Project2.dpr(18): Undeclared identifier: 'self'
So can somebody tell me how to create a component in console appl ?

Comments

  • : [b][red]This message was edited by bogdanul2003 at 2004-5-9 1:25:36[/red][/b][hr]
    : is it possibel to make an delphi appl wich first has a form and then remove the form.I want to do this becouse my application doesn't need a main form(the exe file of a simple appl whith only one form ocupies about 351 kb).If i remove the main form i'll still need to be abel to use unit's like IdComponent,IdTCPConnection,IdTCPClient,tlhelp32,psapi, ScktComp
    : Can this be done ?
    :
    : If not the pls tell me how to cteate a new component in a console application.For eg:ClientSocket1:TClientSocket;
    : ClientSocket1.create();
    : What must the create() param because when i try ClientSocket1.create(self); it passes this error:[Error] Project2.dpr(18): Undeclared identifier: 'self'
    : So can somebody tell me how to create a component in console appl ?
    :
    The best way to create a console application is to use the File|New... command and select "Console Application" from the dialog.
    You can add all the units you need to the uses list.
    The Self identifier only exists within methods, so it cannot be used in procedures, functions or the main program body. To create a component outside a form or datamodule, simply use a nil owner. So you can create a ClientSocket in the following way:
    [code]
    ClientSocket1 := TClientSocket.Create(nil);
    [/code]
    The code you used above will create an Access Violation error, since ClientSocket1 doesn't exist as an instance yet.
    Hint: To reduce the chances of error, I would suggest that you use more descriptive names than the standard component names.
  • : : [b][red]This message was edited by bogdanul2003 at 2004-5-9 1:25:36[/red][/b][hr]
    : : is it possibel to make an delphi appl wich first has a form and then remove the form.I want to do this becouse my application doesn't need a main form(the exe file of a simple appl whith only one form ocupies about 351 kb).If i remove the main form i'll still need to be abel to use unit's like IdComponent,IdTCPConnection,IdTCPClient,tlhelp32,psapi, ScktComp
    : : Can this be done ?
    : :
    : : If not the pls tell me how to cteate a new component in a console application.For eg:ClientSocket1:TClientSocket;
    : : ClientSocket1.create();
    : : What must the create() param because when i try ClientSocket1.create(self); it passes this error:[Error] Project2.dpr(18): Undeclared identifier: 'self'
    : : So can somebody tell me how to create a component in console appl ?
    : :
    : The best way to create a console application is to use the File|New... command and select "Console Application" from the dialog.
    : You can add all the units you need to the uses list.
    : The Self identifier only exists within methods, so it cannot be used in procedures, functions or the main program body. To create a component outside a form or datamodule, simply use a nil owner. So you can create a ClientSocket in the following way:
    : [code]
    : ClientSocket1 := TClientSocket.Create(nil);
    : [/code]
    : The code you used above will create an Access Violation error, since ClientSocket1 doesn't exist as an instance yet.
    : Hint: To reduce the chances of error, I would suggest that you use more descriptive names than the standard component names.
    :

    10x for your advice.Now i have another question.
    How do I assign a procedure to an event in console appl?
    For ex ClientSocket1.onconnect:=?
  • : : : [b][red]This message was edited by bogdanul2003 at 2004-5-9 1:25:36[/red][/b][hr]
    : : : is it possibel to make an delphi appl wich first has a form and then remove the form.I want to do this becouse my application doesn't need a main form(the exe file of a simple appl whith only one form ocupies about 351 kb).If i remove the main form i'll still need to be abel to use unit's like IdComponent,IdTCPConnection,IdTCPClient,tlhelp32,psapi, ScktComp
    : : : Can this be done ?
    : : :
    : : : If not the pls tell me how to cteate a new component in a console application.For eg:ClientSocket1:TClientSocket;
    : : : ClientSocket1.create();
    : : : What must the create() param because when i try ClientSocket1.create(self); it passes this error:[Error] Project2.dpr(18): Undeclared identifier: 'self'
    : : : So can somebody tell me how to create a component in console appl ?
    : : :
    : : The best way to create a console application is to use the File|New... command and select "Console Application" from the dialog.
    : : You can add all the units you need to the uses list.
    : : The Self identifier only exists within methods, so it cannot be used in procedures, functions or the main program body. To create a component outside a form or datamodule, simply use a nil owner. So you can create a ClientSocket in the following way:
    : : [code]
    : : ClientSocket1 := TClientSocket.Create(nil);
    : : [/code]
    : : The code you used above will create an Access Violation error, since ClientSocket1 doesn't exist as an instance yet.
    : : Hint: To reduce the chances of error, I would suggest that you use more descriptive names than the standard component names.
    : :
    :
    : 10x for your advice.Now i have another question.
    : How do I assign a procedure to an event in console appl?
    : For ex ClientSocket1.onconnect:=?
    :
    The short answer is you cannot do that.
    Now for the longer answer. Each event is a method, so you need to create your procedure into a method. This means that you need to create one or more object(s), which is/are going to hold all the methods you need. Here is an example of 1 object only:
    [code]
    type
    TMethodHandler = class(TObject)
    private
    public
    procedure SocketConnect(Sender: TObject; Socket: TCustomWinSocket);
    end;

    procedure TMethodHandler.SocketConnect(Sender: TObject; Socket: TCustomWinSocket);
    begin
    writeln('Successful connection');
    // or whatever you want to do in this event
    end;

    // Program body
    var
    MethodHandler: TMethodHandler;
    begin
    MethodHandler := TMethodHandler.Create;
    // Make sure all the event pointers are correctly initialized
    // DO NOT CALL ANY EVENTS BEFORE THIS POINT!
    Socket.OnConnect := MethodHandler.SocketConnect;
    // Add the event to the socket as normal
    { Execute the program }
    MethodHandler.Free;
    // Free all the event pointers.
    // DO NOT CALL ANY EVENTS AFTER THIS POINT!
    end.
    [/code]
    This is a work-around to the problem, that events are always methods. It is best to start by creating the MethodHandler object as the first statement in the program and to end with freeing it as the last statement.
  • : : : : [b][red]This message was edited by bogdanul2003 at 2004-5-9 1:25:36[/red][/b][hr]
    : : : : is it possibel to make an delphi appl wich first has a form and then remove the form.I want to do this becouse my application doesn't need a main form(the exe file of a simple appl whith only one form ocupies about 351 kb).If i remove the main form i'll still need to be abel to use unit's like IdComponent,IdTCPConnection,IdTCPClient,tlhelp32,psapi, ScktComp
    : : : : Can this be done ?
    : : : :
    : : : : If not the pls tell me how to cteate a new component in a console application.For eg:ClientSocket1:TClientSocket;
    : : : : ClientSocket1.create();
    : : : : What must the create() param because when i try ClientSocket1.create(self); it passes this error:[Error] Project2.dpr(18): Undeclared identifier: 'self'
    : : : : So can somebody tell me how to create a component in console appl ?
    : : : :
    : : : The best way to create a console application is to use the File|New... command and select "Console Application" from the dialog.
    : : : You can add all the units you need to the uses list.
    : : : The Self identifier only exists within [red]methods[/red], so it cannot be used in procedures, functions or the main program body. To create a component outside a form or datamodule, simply use a nil owner. So you can create a ClientSocket in the following way:
    : : : [code]
    : : : ClientSocket1 := TClientSocket.Create(nil);
    : : : [/code]
    : : : The code you used above will create an Access Violation error, since ClientSocket1 doesn't exist as an instance yet.
    : : : Hint: To reduce the chances of error, I would suggest that you use more descriptive names than the standard component names.
    : : :
    : :
    : : 10x for your advice.Now i have another question.
    : : How do I assign a procedure to an event in console appl?
    : : For ex ClientSocket1.onconnect:=?
    : :
    : The short answer is you cannot do that.
    : Now for the longer answer. Each event is a method, so you need to create your procedure into a [red]method[/red]. This means that you need to create one or more object(s), which is/are going to hold all the methods you need. Here is an example of 1 object only:
    : [code]
    : type
    : TMethodHandler = class(TObject)
    : private
    : public
    : procedure SocketConnect(Sender: TObject; Socket: TCustomWinSocket);
    : end;
    :
    : procedure TMethodHandler.SocketConnect(Sender: TObject; Socket: TCustomWinSocket);
    : begin
    : writeln('Successful connection');
    : // or whatever you want to do in this event
    : end;
    :
    : // Program body
    : var
    : MethodHandler: TMethodHandler;
    : begin
    : MethodHandler := TMethodHandler.Create;
    : // Make sure all the event pointers are correctly initialized
    : // DO NOT CALL ANY EVENTS BEFORE THIS POINT!
    : Socket.OnConnect := MethodHandler.SocketConnect;
    : // Add the event to the socket as normal
    : { Execute the program }
    : MethodHandler.Free;
    : // Free all the event pointers.
    : // DO NOT CALL ANY EVENTS AFTER THIS POINT!
    : end.
    : [/code]
    : This is a work-around to the problem, that events are always methods. It is best to start by creating the MethodHandler object as the first statement in the program and to end with freeing it as the last statement.
    :
    the words in [red]red[/red] should be "class" or "object"
    the word "method" means a procedure or function
    ...just a note
    ;-)
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • : : : : : [b][red]This message was edited by bogdanul2003 at 2004-5-9 1:25:36[/red][/b][hr]
    : : : : : is it possibel to make an delphi appl wich first has a form and then remove the form.I want to do this becouse my application doesn't need a main form(the exe file of a simple appl whith only one form ocupies about 351 kb).If i remove the main form i'll still need to be abel to use unit's like IdComponent,IdTCPConnection,IdTCPClient,tlhelp32,psapi, ScktComp
    : : : : : Can this be done ?
    : : : : :
    : : : : : If not the pls tell me how to cteate a new component in a console application.For eg:ClientSocket1:TClientSocket;
    : : : : : ClientSocket1.create();
    : : : : : What must the create() param because when i try ClientSocket1.create(self); it passes this error:[Error] Project2.dpr(18): Undeclared identifier: 'self'
    : : : : : So can somebody tell me how to create a component in console appl ?
    : : : : :
    : : : : The best way to create a console application is to use the File|New... command and select "Console Application" from the dialog.
    : : : : You can add all the units you need to the uses list.
    : : : : The Self identifier only exists within [red]methods[/red], so it cannot be used in procedures, functions or the main program body. To create a component outside a form or datamodule, simply use a nil owner. So you can create a ClientSocket in the following way:
    : : : : [code]
    : : : : ClientSocket1 := TClientSocket.Create(nil);
    : : : : [/code]
    : : : : The code you used above will create an Access Violation error, since ClientSocket1 doesn't exist as an instance yet.
    : : : : Hint: To reduce the chances of error, I would suggest that you use more descriptive names than the standard component names.
    : : : :
    : : :
    : : : 10x for your advice.Now i have another question.
    : : : How do I assign a procedure to an event in console appl?
    : : : For ex ClientSocket1.onconnect:=?
    : : :
    : : The short answer is you cannot do that.
    : : Now for the longer answer. Each event is a method, so you need to create your procedure into a [red]method[/red]. This means that you need to create one or more object(s), which is/are going to hold all the methods you need. Here is an example of 1 object only:
    : : [code]
    : : type
    : : TMethodHandler = class(TObject)
    : : private
    : : public
    : : procedure SocketConnect(Sender: TObject; Socket: TCustomWinSocket);
    : : end;
    : :
    : : procedure TMethodHandler.SocketConnect(Sender: TObject; Socket: TCustomWinSocket);
    : : begin
    : : writeln('Successful connection');
    : : // or whatever you want to do in this event
    : : end;
    : :
    : : // Program body
    : : var
    : : MethodHandler: TMethodHandler;
    : : begin
    : : MethodHandler := TMethodHandler.Create;
    : : // Make sure all the event pointers are correctly initialized
    : : // DO NOT CALL ANY EVENTS BEFORE THIS POINT!
    : : Socket.OnConnect := MethodHandler.SocketConnect;
    : : // Add the event to the socket as normal
    : : { Execute the program }
    : : MethodHandler.Free;
    : : // Free all the event pointers.
    : : // DO NOT CALL ANY EVENTS AFTER THIS POINT!
    : : end.
    : : [/code]
    : : This is a work-around to the problem, that events are always methods. It is best to start by creating the MethodHandler object as the first statement in the program and to end with freeing it as the last statement.
    : :
    : the words in [red]red[/red] should be "class" or "object"
    : the word "method" means a procedure or function
    : ...just a note
    : ;-)
    : [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]
    :
    :
    A method is a procedure/function, which has been declared as part of an object. The help files generally list three things for components: properties, methods, and events. Also people generally speak of "virtual methods" instead of "virtual procedures/functions".
    The words procedure or function denote "stand-alone" pieces of code.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories