Выпонение кода на Delphi без нажатия на Button

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by Андрей021, 14 Jan 2010.

  1. Андрей021

    Андрей021 New Member

    Joined:
    3 Aug 2009
    Messages:
    13
    Likes Received:
    2
    Reputations:
    1
    Как сделать, что бы этот код выполнился при запуске программы, без нажатия на Button, и убрать интерфейс :confused:

    Code:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Registry, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
      reg: TRegistry;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
       reg:=tregistry.create;
       reg.rootkey:=hkey_current_user;
       if reg.openkey('software\My Project', true) then
       begin
           reg.WriteString('parameter', 'value');
           reg.closekey;
       end;
       reg.free;
    end;
    
    end.
    
     
    #1 Андрей021, 14 Jan 2010
    Last edited: 14 Jan 2010
  2. GlooK

    GlooK Elder - Старейшина

    Joined:
    20 Apr 2007
    Messages:
    172
    Likes Received:
    53
    Reputations:
    10
    Создай консольный проект и убери строчку {$APPTYPE CONSOLE}.
    Одним выстрелом убьешь двух зайцев :)
     
  3. s0l_ir0n

    s0l_ir0n Active Member

    Joined:
    14 Mar 2009
    Messages:
    399
    Likes Received:
    144
    Reputations:
    18
    Code:
    program Project1;
    uses
      registry;
    var
      reg: TRegistry;
    const
    HKEY_CURRENT_USER     = $80000001;
    begin
    reg:=tregistry.create;
       reg.rootkey:=hkey_current_user;
       if reg.openkey('software\My Project', true) then
       begin
           reg.WriteString('parameter', 'value');
           reg.closekey;
       end;
       reg.free;
    end.
     
  4. 0ldbi4

    0ldbi4 Elder - Старейшина

    Joined:
    14 Apr 2008
    Messages:
    264
    Likes Received:
    51
    Reputations:
    10
    используй события которые происходят при старте приложения
     
  5. Андрей021

    Андрей021 New Member

    Joined:
    3 Aug 2009
    Messages:
    13
    Likes Received:
    2
    Reputations:
    1
    Всем спасибо, вопрос решён :)
     
  6. flacs

    flacs Member

    Joined:
    28 Jan 2009
    Messages:
    81
    Likes Received:
    31
    Reputations:
    6
    или консоль, или Form.OnCreate, OnShow
     
    1 person likes this.
Loading...