Kod: Tümünü seç
btnMASA := TButton.Create(FlowPanel1);
Kod: Tümünü seç
btnMASA := TButton.Create(Self);
Kod: Tümünü seç
btnMASA := TButton.Create(FlowPanel1);
Kod: Tümünü seç
btnMASA := TButton.Create(Self);
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels,
cxLookAndFeelPainters, cxStyles, cxCustomData, cxFilter, cxData,
cxDataStorage, cxEdit, cxNavigator, dxDateRanges, Data.DB, cxDBData,
Vcl.StdCtrls, Vcl.Mask, Vcl.DBCtrls, cxGridLevel, cxGridCustomTableView,
cxGridTableView, cxGridDBTableView, cxClasses, cxGridCustomView, cxGrid,
DBAccess, Uni, SQLServerUniProvider, UniProvider, ODBCUniProvider,
AccessUniProvider, MemDS, Vcl.ExtCtrls, Vcl.Grids, Vcl.DBGrids, Vcl.Menus,
cxButtons;
type
TForm1 = class(TForm)
srcQRY_SIPARISLER: TUniDataSource;
QRY_RS_MASALAR: TUniQuery;
AccessUniProvider1: TAccessUniProvider;
SQLServerUniProvider1: TSQLServerUniProvider;
DB: TUniConnection;
Button1: TButton;
Button2: TButton;
Button3: TButton;
FlowPanel1: TFlowPanel;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
type
TPanel = class(Vcl.extCtrls.TPanel)
private
FBilgi: integer;
public
property Bilgi: integer read FBilgi write FBilgi;
end;
private
{ Private declarations }
procedure OnMasaClick(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
MASA: Integer;
btnMASA: TPanel;
begin
for MASA := 1 to QRY_RS_MASALAR.RecordCount do
begin
btnMASA := TPanel.Create(FlowPanel1);
// btnMASA := TPanel.Create(Self);
btnMASA.Parent := FlowPanel1;
btnMASA.Caption := QRY_RS_MASALAR.FieldByName('MASA_ADI').Text;
btnMASA.Height := 100;
btnMASA.Width := 100;
btnMASA.Bilgi:=Self.Tag;
btnMASA.OnClick:=OnMasaClick;
Self.Tag:=Self.Tag + 1;
QRY_RS_MASALAR.Next;
end;
end;
procedure TForm1.OnMasaClick(Sender: TObject);
var
i:integer;
Begin
if Sender is TPanel then
Caption:= TPanel(Sender).Bilgi.ToString;
for i := 0 to ComponentCount-1 do
begin
if (Components is TPanel) AND (TPanel(Components).Tag=10) Then
Begin
TPanel(Components).Caption :='BtnNamexx';
TPanel(Components).Color :=clGreen;
// TButton( Components).Free; // Silmek için..
End;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
QRY_RS_MASALAR.Open;
QRY_RS_MASALAR.Refresh;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i:integer;
Begin
if Sender is TPanel then
Caption:= TPanel(Sender).Bilgi.ToString;
for i := 0 to ComponentCount-1 do
begin
if (Components is TPanel) Then
Begin
TPanel( Components).Free; // Silmek için..
End;
end;
end;
end.
İlgili kod hatalı. Oluşturulan butonların tag değerini değil Form'un tag değerini değiştiriyor. Doğrusu aşağıdaki gibi olmalı:erdogan_ozkaya yazdı: ↑25 Şub 2020 09:46 Arkadaşlar,
aşağıdaki kod ile buton üretiyorum, ürettiğim butonun tag ını buluyorum yapmak istediğim tag ını bulduğum butonun rengini ve adını değiştirmek ?
birde ürettiğim tüm butonları silmek istiyorum ?
Teşekkürler
Kod: Tümünü seç
procedure TForm1.Button1Click(Sender: TObject); var MASA: Integer; btnMASA: TButton; begin for MASA := 1 to QRY_RS_MASALAR.RecordCount do begin btnMASA := TButton.Create(FlowPanel1); btnMASA.Parent := FlowPanel1; btnMASA.Caption := QRY_RS_MASALAR.FieldByName('MASA_ADI').Text; btnMASA.Height := 100; btnMASA.Width := 100; btnMASA.Info2:=Self.Tag; btnMASA.OnClick:=OnMasaClick; Self.Tag:=Self.Tag + 1; QRY_RS_MASALAR.Next; end; end; procedure TForm1.OnMasaClick(Sender: TObject); begin if Sender is TButton then Caption:= TButton(Sender).Bilgi.ToString; end;
Kod: Tümünü seç
procedure TForm1.Button1Click(Sender: TObject);
var
MASA: Integer;
btnMASA: TButton;
begin
for MASA := 1 to QRY_RS_MASALAR.RecordCount do
begin
btnMASA := TButton.Create(FlowPanel1);
btnMASA.Parent := FlowPanel1;
btnMASA.Caption := QRY_RS_MASALAR.FieldByName('MASA_ADI').Text;
btnMASA.Height := 100;
btnMASA.Width := 100;
btnMASA.Info2:=Self.Tag;
btnMASA.OnClick:=OnMasaClick;
btnMASA.Tag := MASA;
QRY_RS_MASALAR.Next;
end;
end;
Kod: Tümünü seç
function TForm1.GetButtonByTag(Parent: TFlowPanel; const Tag: Integer): TButton;
var
I: Integer;
begin
for I := 0 to Parent.ComponentCount-1 do
begin
if (Parent.Components[I] is TButton) then
if TButton(Parent.Components[I]).Tag = Tag then
Exit(TButton(Parent.Components[I]));
end;
Result := nil;
end;
Kod: Tümünü seç
procedure TForm1.Test();
var
Buton: TButton;
begin
Buton := GetButtonByTag(FlowPanel1, 10);
if Buton <> nil then
begin
Buton.Color := clGreen;
end;
end;
Kod: Tümünü seç
procedure TForm1.Test2();
var
Buton: TButton;
begin
Buton := GetButtonByTag(FlowPanel1, 10);
if Buton <> nil then
begin
Buton.Free();
end;
end;
"Hata" olarak çok farklı hatalar mevcut. Derleme zamanında oluşanlardan tutun çalışma zamanında oluşanlara kadar.erdogan_ozkaya yazdı: ↑25 Şub 2020 12:47 Hocam Çok teşekkür ederim,
bu kısımı hata veriyor Buton := GetButtonByTag(FlowPanel1, 10);
Kod: Tümünü seç
[dcc32 Error] Unit1.pas(120): E2010 Incompatible types: 'Integer' and 'string'
Kod: Tümünü seç
[dcc32 Error] Unit1.pas(131): E2010 Incompatible types: 'TForm1.TButton' and 'TButton'