Sayfayı Yazdır | Pencereyi Kapat

Dinamik Bileşende işlem

Nereden Yazdırıldığı: Clomosy | Forum
Kategori: Genel Programlama
Forum Adı: Clomosy ile değişken kullanımı
Forum Tanımlaması: TRObject dili ile değişken tanımlaması ve ekranda gösterme
URL: https://forum.clomosy.com.tr/forum_posts.asp?TID=1225
Tarih: 12 Kasım 2025 Saat 21:34
Program Versiyonu: Web Wiz Forums 12.07 - https://www.webwizforums.com


Konu: Dinamik Bileşende işlem
Mesajı Yazan: M-Guney
Konu: Dinamik Bileşende işlem
Mesaj Tarihi: 12 Kasım 2025 Saat 16:40
Dinamik olarak oluşan panelime artı eksi butonları ekledim ve o butonlara tıklanma durumunda miktarı artırmak için bu kodu yazdım fakat arasında gecikme oluyor daha iyi bir yöntem var mı Örnek olarak hint ile ulaşmayı denedim fakat access violation hatası verdi.

void ChangeItemAmountV(APieces : Integer)
var
 TempPieceLbl : TclProLabel;
 LPieceStr : String;
{
  //ShowMessage(ComponentName);
  TempPieceLbl = MainForm.clFindComponent(ComponentName) as TclProLabel; //'PieceLbl'+IntToStr(I)
  LPieceStr = TempPieceLbl.Text;
  Delete(LPieceStr,1,1); //Delete x letter from piecesLbl
  if((APieces>0)||(StrToInt(LPieceStr)>0))
    LPieceStr = StrToInt(LPieceStr) + APieces;
  Insert('x', LPieceStr,0);// Add x 
  TempPieceLbl.Text = LPieceStr;
   
  //ShowMessage(LPieceStr);
}
void ItemDecreaseV
{
  ChangeItemAmountV(-1);
}
void ItemIncreaseV
{
  ChangeItemAmountV(1);
}

IncreaseBtn = MainForm.AddNewProButton(ValuePnl,'IncreaseBtn'+IntToStr(I),'+');
      //IncreaseBtn.Width = 38;
      IncreaseBtn.Width = (MainForm.clWidth * 0.0967);
      //IncreaseBtn.Height = 38;
      IncreaseBtn.Height = (MainForm.clHeight * 0.0453);
      //IncreaseBtn.Margins.Bottom=40;
      IncreaseBtn.Margins.Bottom = (MainForm.clHeight * 0.0477);
      IncreaseBtn.clProSettings.BorderWidth = 2;
      IncreaseBtn.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#1e1e1e');
      IncreaseBtn.clProSettings.BorderColor = clAlphaColor.clHexToColor('#3a3a3a');
      IncreaseBtn.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
      IncreaseBtn.clProSettings.FontSize = 20;
      IncreaseBtn.SetclProSettings(IncreaseBtn.clProSettings);
      MainForm.AddNewEvent(IncreaseBtn,tbeOnClick,'ItemIncreaseV');
      IncreaseBtn.clTagStr = 'Inc';
      IncreaseBtn.clTagInt = StrToInt( FieldByName('item_id').AsString );
      IncreaseBtn.hint = 'PieceLbl'+IntToStr(I);
      ComponentName = IncreaseBtn.hint;
      
      DecreaseBtn = MainForm.AddNewProButton(ValuePnl,'DecreaseBtn'+IntToStr(I),'-');
      //DecreaseBtn.Width = 38;
      DecreaseBtn.Width = (MainForm.clWidth * 0.0967);
      //DecreaseBtn.Height = 38;
      DecreaseBtn.Height = (MainForm.clHeight * 0.0453);
      //DecreaseBtn.Margins.top=40;
      DecreaseBtn.Margins.top = (MainForm.clHeight * 0.0500);
      DecreaseBtn.clProSettings.BorderWidth = 2;
      DecreaseBtn.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#1e1e1e');
      DecreaseBtn.clProSettings.BorderColor = clAlphaColor.clHexToColor('#3a3a3a');
      DecreaseBtn.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
      DecreaseBtn.clProSettings.FontSize = 20;
      DecreaseBtn.SetclProSettings(DecreaseBtn.clProSettings);
      MainForm.AddNewEvent(DecreaseBtn,tbeOnClick,'ItemDecreaseV');
      DecreaseBtn.clTagStr = 'Dec';
      
      
      PieceLbl = MainForm.AddNewProLabel(DetailsPnl,'PieceLbl'+IntToStr(I), 'x' + FieldByName('amount').AsString ); //HERE
      //PieceLbl.Width = 25;
      PieceLbl.Width = (MainForm.clWidth * 0.0636);
      //PieceLbl.Height = 25;
      PieceLbl.Height = (MainForm.clHeight * 0.0298);
      //PieceLbl.Margins.Left=160;
      PieceLbl.Margins.Left= (MainForm.clWidth * 0.4071);
      //PieceLbl.Margins.top=35;
      PieceLbl.Margins.top= (MainForm.clHeight * 0.0417);
      PieceLbl.clProSettings.FontSize = 16;
      //PieceLbl.clTagStr = 'PieceLbl'+IntToStr(I);
      PieceLbl.clProSettings.FontVertAlign = palcenter;
      PieceLbl.clProSettings.FontHorzAlign = palLeading;
      PieceLbl.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
      PieceLbl.clProSettings.TextSettings.Font.Style = [fsBold];
      //PieceLbl.text=IntToStr(piece);
      PieceLbl.SetclProSettings(PieceLbl.clProSettings);
      PieceLbl.clTagStr = 'PieceLbl'+IntToStr(I);
https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">



Cevaplar:
Mesajı Yazan: Emr.Erkmn
Mesaj Tarihi: 12 Kasım 2025 Saat 17:30
bende senin gibi 
clTagStr kullandım 
bu şekil de yazdırdım 
IncreaseBtn = MainForm.AddNewProButton(ValuePnl, 'IncreaseBtn' + IntToStr(I), '+');
IncreaseBtn.Width = (MainForm.clWidth * 0.0967);
IncreaseBtn.Height = (MainForm.clHeight * 0.0453);
IncreaseBtn.Margins.Bottom = (MainForm.clHeight * 0.0477);
IncreaseBtn.clProSettings.BorderWidth = 2;
IncreaseBtn.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#1e1e1e');
IncreaseBtn.clProSettings.BorderColor = clAlphaColor.clHexToColor('#3a3a3a');
IncreaseBtn.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
IncreaseBtn.clProSettings.FontSize = 20;
IncreaseBtn.SetclProSettings(IncreaseBtn.clProSettings);

MainForm.AddNewEvent(IncreaseBtn, tbeOnClick, 'ItemIncreaseV');

// lTagStr'ye label ismini kaydet 
IncreaseBtn.clTagStr = 'PieceLbl' + IntToStr(I);
IncreaseBtn.clTagInt = I;  // Index'i de kaydet 

DecreaseBtn = MainForm.AddNewProButton(ValuePnl, 'DecreaseBtn' + IntToStr(I), '-');
DecreaseBtn.Width = (MainForm.clWidth * 0.0967);
DecreaseBtn.Height = (MainForm.clHeight * 0.0453);
DecreaseBtn.Margins.Top = (MainForm.clHeight * 0.0500);
DecreaseBtn.clProSettings.BorderWidth = 2;
DecreaseBtn.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#1e1e1e');
DecreaseBtn.clProSettings.BorderColor = clAlphaColor.clHexToColor('#3a3a3a');
DecreaseBtn.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
DecreaseBtn.clProSettings.FontSize = 20;
DecreaseBtn.SetclProSettings(DecreaseBtn.clProSettings);

MainForm.AddNewEvent(DecreaseBtn, tbeOnClick, 'ItemDecreaseV');

// clTagStr'ye label ismini kaydet
DecreaseBtn.clTagStr = 'PieceLbl' + IntToStr(I);
DecreaseBtn.clTagInt = I;  // Index'i de kaydet 

https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">


Mesajı Yazan: Emr.Erkmn
Mesaj Tarihi: 12 Kasım 2025 Saat 17:31
Global değişken yok her buton kendi clTagStr değerini kullandığı için 
ClSender hangi butona tıklandığını buluyor
ClTagStr daha hızlı şu an  https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">


Mesajı Yazan: Emr.Erkmn
Mesaj Tarihi: 12 Kasım 2025 Saat 17:37
void ChangeItemAmountV_Safe(APieces : Integer)
var
  TempPieceLbl : TclProLabel;
  TempButton: TclProButton;
  labelName: String;
  LPieceStr : String;
  currentAmount: Integer;
{
  Try
    if (MainForm.ClSender == nil)
    {
      Exit;
    }
    
    TempButton = MainForm.ClSender as TclProButton;
    
    if (TempButton == nil)
    {
      Exit;
    }
    
    Try
      labelName = TempButton.Hint;
    except
      Exit;
    }
    
    if (Trim(labelName) == '')
    {
      Exit;
    }
    
    TempPieceLbl = MainForm.clFindComponent(labelName) as TclProLabel;
    
    if (TempPieceLbl == nil)
    {
      Exit;
    }
    
    LPieceStr = TempPieceLbl.Text;
    
    if (Pos('x', LPieceStr) == 1)
    {
      LPieceStr = Copy(LPieceStr, 2, Length(LPieceStr) - 1);
    }
    
    Try
      currentAmount = StrToInt(Trim(LPieceStr));
    except
      currentAmount = 0;
    }
    
    // Miktarı güncelle
    currentAmount = currentAmount + APieces;
    
    if (currentAmount < 0)
    {
      currentAmount = 0;
    }
    
    TempPieceLbl.Text = 'x' + IntToStr(currentAmount);
  except
    // Sessizce devam et
  }
}
void ItemDecreaseV
{
  ChangeItemAmountV_Safe(-1);
}

void ItemIncreaseV
{
  ChangeItemAmountV_Safe(1);
}

//  BUTON OLUŞTURMA - HINT İLE

void CreateButtonsWithHint(I: Integer)
var
  IncreaseBtn, DecreaseBtn: TclProButton;
  PieceLbl: TclProLabel;
{
  Try
    IncreaseBtn = MainForm.AddNewProButton(ValuePnl, 'IncreaseBtn' + IntToStr(I), '+');
    IncreaseBtn.Width = (MainForm.clWidth * 0.0967);
    IncreaseBtn.Height = (MainForm.clHeight * 0.0453);
    IncreaseBtn.Margins.Bottom = (MainForm.clHeight * 0.0477);
    IncreaseBtn.clProSettings.BorderWidth = 2;
    IncreaseBtn.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#1e1e1e');
    IncreaseBtn.clProSettings.BorderColor = clAlphaColor.clHexToColor('#3a3a3a');
    IncreaseBtn.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
    IncreaseBtn.clProSettings.FontSize = 20;
    IncreaseBtn.SetclProSettings(IncreaseBtn.clProSettings);
    
    MainForm.AddNewEvent(IncreaseBtn, tbeOnClick, 'ItemIncreaseV');
    
    IncreaseBtn.Hint = 'PieceLbl' + IntToStr(I);
    
    IncreaseBtn.clTagInt = I;
    
    DecreaseBtn = MainForm.AddNewProButton(ValuePnl, 'DecreaseBtn' + IntToStr(I), '-');
    DecreaseBtn.Width = (MainForm.clWidth * 0.0967);
    DecreaseBtn.Height = (MainForm.clHeight * 0.0453);
    DecreaseBtn.Margins.Top = (MainForm.clHeight * 0.0500);
    DecreaseBtn.clProSettings.BorderWidth = 2;
    DecreaseBtn.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#1e1e1e');
    DecreaseBtn.clProSettings.BorderColor = clAlphaColor.clHexToColor('#3a3a3a');
    DecreaseBtn.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
    DecreaseBtn.clProSettings.FontSize = 20;
    DecreaseBtn.SetclProSettings(DecreaseBtn.clProSettings);
    
    MainForm.AddNewEvent(DecreaseBtn, tbeOnClick, 'ItemDecreaseV');
    
    DecreaseBtn.Hint = 'PieceLbl' + IntToStr(I);
    
    DecreaseBtn.clTagInt = I;
    
    PieceLbl = MainForm.AddNewProLabel(DetailsPnl, 'PieceLbl' + IntToStr(I), 'x' + FieldByName('amount').AsString);
    PieceLbl.Width = (MainForm.clWidth * 0.0636);
    PieceLbl.Height = (MainForm.clHeight * 0.0298);
    PieceLbl.Margins.Left = (MainForm.clWidth * 0.4071);
    PieceLbl.Margins.Top = (MainForm.clHeight * 0.0417);
    PieceLbl.clProSettings.FontSize = 16;
    PieceLbl.clProSettings.FontVertAlign = palcenter;
    PieceLbl.clProSettings.FontHorzAlign = palLeading;
    PieceLbl.clProSettings.FontColor = clAlphaColor.clHexToColor('#ffffff');
    PieceLbl.clProSettings.TextSettings.Font.Style = [fsBold];
    PieceLbl.SetclProSettings(PieceLbl.clProSettings);
  except
    ShowMessage('CreateButtonsWithHint hatası: ' + LastExceptionMessage);
  }
}



Sayfayı Yazdır | Pencereyi Kapat

Forum Software by Web Wiz Forums® version 12.07 - https://www.webwizforums.com
Copyright ©2001-2024 Web Wiz Ltd. - https://www.webwiz.net