小编Alv*_*Lin的帖子

Delphi - 如何在运行时删除所有子组件?

在设计时,我创建了一个TScrollBox,它将成为运行时创建的TLayouts的父级.布局还包含Tlabels和Tedits,如下所示:

var
  Layout1: TLayout;
  Label1: TLabel;
  Edit1: TEdit;
begin
  Layout1 := TLayout.Create(self);
  Layout1.Parent := ScrollBox1;
  Label1 := TLabel.Create(self);
  Label1.Parent := Layout1;
  Label1.Text := 'abc';
end;
Run Code Online (Sandbox Code Playgroud)

现在我想要删除所有内容,就像从未调用此过程一样.

我试过以下,但程序会崩溃.

var
  i : integer;
  Item : TControl;
begin
  for i := 0 to Scrollbox1.ControlCount - 1 do  
  begin  
    Item := Scrollbox1.controls[i];
    Item.Free;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

任何人都可以给我一个提示吗?

delphi components vcl runtime

5
推荐指数
1
解决办法
9941
查看次数

Delphi:数据库被锁定(SQLite)

我面临两个问题......

(1)当我尝试使用Delphi XE6写入数据库(SQLite)时,我总是得到数据库被锁定的错误消息.我确信每次使用FDConnection1.Close命令访问数据库时都会关闭数据库.

(2)如何从传入参数中插入表格?我有以下传入参数

procedure TStock_Bookkeeping.Write_To_DB(const Stock_Code, Stock_Name,
Tran_Date, Buy_Sell, Price_Per_Share, Num_Shares, Trans_Fee: string);
Run Code Online (Sandbox Code Playgroud)

并尝试使用以下SQL命令写入表:

sSQL := 'INSERT INTO Each_Stock_Owned(Stock_Code, Stock_Name, Tran_Date, Buy_Sell,
         Price_Per_Share, Num_Shares, Trans_Fee) 
         VALUES (Stock_Code, Stock_Name, Tran_Date, Buy_Sell, Price_Per_Share,  
         Num_Shares, Trans_Fee)';
Run Code Online (Sandbox Code Playgroud)

但它似乎不起作用......

以下是我遇到问题的完整程序

procedure TStock_Bookkeeping.Write_To_DB(const Stock_Code, Stock_Name,
  Tran_Date, Buy_Sell, Price_Per_Share, Num_Shares, Trans_Fee: string);
var
  query : TFDQuery;
  sSQL: string;
begin
    query := TFDQuery.Create(nil);
  try
    ConnectToSQLite;
    query.Connection := FDConnection1;
  if Stock_Code.IsEmpty then
    ShowMessage('Stock Code Cannot Be Empty')
    else
      if Stock_Name.IsEmpty then
        ShowMessage('Stock Name Cannot Be Empty')
        else
          if …
Run Code Online (Sandbox Code Playgroud)

database delphi sqlite database-locking

1
推荐指数
1
解决办法
7192
查看次数

德尔福:你如何控制多个相似的对象?

假设我有五个TRectangle对象,并且一个函数将传入一个参数以使其中一个闪烁.

我知道如何控制一个对象,如下面的代码:

procedure TForm1.TimerTimer(Sender: TObject);
begin
  if rect1.Visible then
    rect1.Visible := false
  else
    rect1.Visible := true;
end;

procedure TForm1.Blink_Square;
begin
  Timer := TTimer.Create(nil);
  Timer.OnTimer := TimerTimer;
  rect1.Fill.Color := TAlphacolors.Red;
  rect1.fill.Kind := TBrushKind.bkSolid;
  rect1.Stroke.Thickness := 1;
  rect1.Stroke.Color := Talphacolors.Darkgray;
  Timer.Interval := 500;
  Timer.Enabled := True;
end;
Run Code Online (Sandbox Code Playgroud)

但我真的不知道,如果有一种方法,我可以重复使用眨眼广场就像有一个步骤,procedure TForm1.Blink_Square(rec_number: integer);我们可以调用Blink_Square(5);rect5眨眼.

提前致谢

delphi firemonkey

0
推荐指数
1
解决办法
358
查看次数

带定时器的单独单元的调用过程

我正在尝试编写一个单独的单元供我的主窗体调用,除了使用TTimer.

基本上,该函数应该做的就是主窗体uDataReceived调用BlinkRect(Gateway)rRectControl单元形式处理,并且相应的矩形将在主窗体中闪烁。

以下是代码:

unit uRectControl;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants, System.IOUtils, FMX.Graphics, FMX.Types, FMX.Objects;

var
  Blinks: array [0 .. 2] of record Rectangle: TRectangle;
  Timer: TTimer;
end;

type
  TMyClass = Class(TObject)
  private
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  public
    procedure BlinkRect(Gateway: integer);
  end;

procedure AssignRectangles;

implementation

uses uDataReceived;
// Error shows "Cannot resolve unit name 'uDataReceived'

{ TMyClass }

procedure AssignRectangles;
var
  i: integer;
begin
  Blinks[0].Rectangle := TC_Theft_Detection.rect1;
  // Error shows …
Run Code Online (Sandbox Code Playgroud)

delphi timer timertask firemonkey delphi-xe7

0
推荐指数
1
解决办法
784
查看次数