Delphi - Как создать кнопку на форме

Ответить
Аватара пользователя
VovanZ

Delphi - Как создать кнопку на форме

Сообщение VovanZ »

Код:

Код: Выделить всё

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  Button1: TButton;
implementation
{$R *.dfm}
begin
  Button1:=StdCtrls.TButton.Create(Form1);
  Button1.Parent:=Form1;
  Button1.Visible:=true;
end.





Почему данный код не создаёт кнопку на форму?
Аватара пользователя
XCodeR

Re: Delphi - Как создать кнопку на форме

Сообщение XCodeR »

VovanZ, отличное название темы. Очень информативное.



По существу,попробуйте указать положение (Left&Top) элемента и добавить следующую строчку

Form1.InsertControl(Button1);
Аватара пользователя
XCodeR

Re: Delphi - Как создать кнопку на форме

Сообщение XCodeR »

Код:

Код: Выделить всё

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Button1: TButton;
implementation
{$R *.dfm}
begin
Button1:=StdCtrls.TButton.Create(Fo rm1);
Button1.Parent:=Form1;
Button1.left:=100;
Button1.top:=100;
Button1.height:=100;
Button1.width:=100;
Button1.Visible:=true;
Button1.Parent := Form1;
end.
Вот так - не помагает;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Button1: TButton;
implementation
{$R *.dfm}
begin
Button1:=StdCtrls.TButton.Create(Fo rm1);
Button1.Parent:=Form1;
Button1.left:=100;
Button1.top:=100;
Button1.height:=100;
Button1.width:=100;
Button1.Visible:=true;
Button1.Parent := Form1;
Form1.InsertControl(Button1);
end.



Вот так - EAccseccViolation
Аватара пользователя
Serega

Re: Delphi - Как создать кнопку на форме

Сообщение Serega »

VovanZ, я не совсем понял, чего вы хотите добиться, если просто создать кнопку, то так:
читать дальше »




Код:

Код: Выделить всё

unit Unit1;
interface
uses
  Classes, Controls, Forms, StdCtrls;
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  Button1: TButton;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1 := TButton.Create(Form1);
  with Button1 do begin
    Left := 50;
    Width := 100;
    Top := 50;
    Height := 25;
    Caption := 'Кнопка';
    Parent := Form1;
  end;
end;
end.
Аватара пользователя
VovanZ

Re: Delphi - Как создать кнопку на форме

Сообщение VovanZ »

Спасибо, я разобрался, тему можно закрыть
Ответить

Вернуться в «Программирование и базы данных»