Delphi Can

Orjinalini görmek için tıklayınız: [Çözüldü] Bileşen var mı yok mu ?
Şu anda (Arşiv) modunu görüntülemektesiniz. Orjinal Sürümü Görüntüle internal link
Sayfalar: 1 2
Üstad yine döktürdü Smile
MrMarman üstadım nefis bir örnek olmuş emeğinize sağlık çok teşekkürler. O sihirli çaydan bende istiyorum Smile

Üstadım gerçekten sağolun fakat projemi Fmx olarak oluşturmuştum. Ve sizin bu örneği ona uyarlamak isterken bilmediğim yerler çıktı ve uyarlayamadım. Örneğin stringgridi create ettiniz bölüm.
Emeğinize bir kez daha teşekkürler
FMX için düzeltme. Dikkatimden hep kaçıyor.


uses
 System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
 FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.TabControl,
 FMX.Layouts, FMX.StdCtrls, FMX.Grid, FMX.Grid.Style, FMX.DialogService;

type
 TForm1 = class(TForm)
   TabControl1: TTabControl;
   TabItem1: TTabItem;
   TabItem2: TTabItem;
   ScrollBox1: TScrollBox;
   ScrollBox2: TScrollBox;
   procedure FormCreate(Sender: TObject);
 private
   procedure YeniStringGrid(  aParentScrollBox: TScrollBox;
                                     aDefValue : String;
                                     aCopyFrom:TPanel = nil );
   procedure OnButtonSatisClick(Sender: TObject);
   procedure OnButtonIadeClick(Sender: TObject);


FMX hali bu şekilde. Idea

procedure TForm1.YeniStringGrid(  aParentScrollBox: TScrollBox;
                                 aDefValue : String;
                                 aCopyFrom:TPanel = nil );
Const
 iColWidth   = 20;
 iRowHeight  = 30;
 iColCount   = 9;
 iRowCount   = 3;
 iTopMargin  = 20;
 iLeftMargin = 4;
var
 i,j,k        : Integer;
 aPanel       : TPanel;
 aLabel       : TLabel;
 aStringGrid  : TStringGrid;
 aButton      : TButton;
 aControl     : TControl;
 aStringColumn: TStringColumn;
begin
 aPanel := TPanel.Create(nil);
 With aPanel do begin
   Parent       := aParentScrollBox;
   Width        := ( (iColWidth +2) * iColCount ) + ( iLeftMargin );
   Height       := ( (iRowHeight+2) * iRowCount ) + ( iTopMargin + 5  );
   Position.X   := ( (aParentScrollBox.Content.ControlsCount-1) mod 5 ) * Trunc(Width);
   Position.Y   := ( (aParentScrollBox.Content.ControlsCount-1) div 5 ) * Trunc(Height);
 end;

 aLabel := TLabel.Create(nil);
 With aLabel do begin
   Parent       := aPanel;
   Position.X   := iLeftMargin;
   Position.Y   := 4;
   Text         :=  'Kart No. ' + IntToStr( aParentScrollBox.Content.ControlsCount );
 end;

 aButton := TButton.Create(nil);
 with aButton do begin
   Parent      := aPanel;
   Width       := 60;
   Height      := 20;
   Text        := 'Satış';
   Position.X  := Trunc(aPanel.Width - iLeftMargin - aButton.Width);
   Position.Y  := 0;
   onClick     := self.OnButtonSatisClick;
 end;

 aStringGrid := TStringGrid.Create(nil);
 With aStringGrid do begin
   Parent     := aPanel;
   Visible    := True;

 //ColCount   := iColCount;
 //for i := 0 to Pred(iColCount) do ColWidths[i]  := iColWidth;
 //for i := 0 to Pred(iRowCount) do RowHeights[i] := iRowHeight;
   for i := 0 to Pred(iColCount) do
   begin
     aStringColumn := TStringColumn.Create(nil);
     aStringColumn.Width := iColWidth;
     AddObject( aStringColumn );
   end;

   RowCount   := iRowCount;
 //ScrollBars := Vcl.StdCtrls.TScrollStyle.ssNone;

 //Options    := [ goVertLine, goHorzLine ];

 //FixedRows:= 0;
 //FixedCols:= 0;
   Width    := ( (iColWidth +2) * iColCount ) - 5;
   Height   := ( (iRowHeight+2) * iRowCount );
   Position.X := iLeftMargin;
   Position.Y := iTopMargin;

   if aDefValue <> '' then
     for i := 0 to Pred(iColCount) do
       for j := 0 to Pred(iRowCount) do
         Cells[i,j] := aDefValue;
 end;

 // Kopyala denmiş ise...
 if aCopyFrom <> nil then
 begin
   aButton.Text     := 'İade';
   aButton.onClick  := self.onButtonIadeClick;

   for k := 0 to Pred( aCopyFrom.ControlsCount) do
   begin
     aControl := aCopyFrom.Controls[k];

     if aControl is TLabel then
     begin
       aLabel.Text := TLabel(aControl).Text;
     end;

     if aControl is TStringGrid then
     begin
       for i := 0 to Pred(iColCount) do
         for j := 0 to Pred(iRowCount) do
           aStringGrid.Cells[i,j] := TStringGrid(aControl).Cells[i,j];
     end;
   end; // for
 end; // if
end;

procedure TForm1.OnButtonSatisClick(Sender: TObject);
var
i : Integer;
aControl : TControl;
begin
for i := 0 to Pred( TPanel(TButton(Sender).Parent).ControlsCount) do
begin
  aControl := TPanel(TButton(Sender).Parent).Controls[i];

  if aControl is TLabel then
  begin
    if MessageDlg( 'Kopyalamak istediğiniz kart "' + TLabel(aControl).Text + '" Onaylayınız...',
                     System.UITypes.TMsgDlgType.mtConfirmation,
                    [System.UITypes.TMsgDlgBtn.mbOk, System.UITypes.TMsgDlgBtn.mbCancel],
                    0 ) = mrOk
    then
    begin
      YeniStringGrid( ScrollBox2, '', TPanel( TButton(Sender).Parent ) );
    end;
  end;
end;
end;

procedure TForm1.OnButtonIadeClick(Sender: TObject);
var
 i, j     : Integer;
 aControl : TControl;
 aPanel   : TPanel;
 aLabel   : TLabel;
begin
 i       := 0;
 aLabel  := nil;
 while ( i <= Pred( TPanel(TButton(Sender).Parent).ControlsCount) ) AND (aLabel = nil) do
 begin
   aControl := TPanel(TButton(Sender).Parent).Controls[i];
   if aControl is TLabel
     then aLabel := TLabel(aControl);
   inc(i);
 end;

 if aLabel <> nil then
 begin
   if MessageDlg( 'Silmek İstediğiniz kart "' + aLabel.Text + '" Onaylayınız...',
                    System.UITypes.TMsgDlgType.mtConfirmation,
                   [System.UITypes.TMsgDlgBtn.mbOk, System.UITypes.TMsgDlgBtn.mbCancel],
                   0 ) = mrOk
   then
   begin
     aPanel   := TPanel( TButton(Sender).Parent );

     for i := Pred( aPanel.ControlsCount ) downto 0 do
     begin
       if aPanel.Controls[i] is TStringGrid then begin
         for j := Pred(TStringGrid(aPanel.Controls[i]).ColumnCount) downto 0
           do TStringGrid(aPanel.Controls[i]).Columns[j].DisposeOf;
           TStringGrid(aPanel.Controls[i]).Free;
       end
       else aPanel.Controls[i].Free;
     end;

     aPanel.Free;
   end; // if Ok
 end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i : Integer;
begin
 for i := 1 to 10
   do YeniStringGrid( ScrollBox1, '0' );
end;
Sayfalar: 1 2