小编Moh*_*enB的帖子

TThread本身的线程安全字段是否安全?

在这段代码中:

TMyClass = class(TThread)
public
  FInputBuffer     : TThreadedQueue<TBytes>;
protected
  procedure Execute; override;
end;
Run Code Online (Sandbox Code Playgroud)

使用(在TMyClass和其他类中)FInputBuffer是线程安全吗?

编辑:

样本使用:在TMyClass中:

procedure TMyClass.Execute;
var x     :TBytes;
begin
  inherited;
  FInputBuffer:= TThreadedQueue<TBytes>.Create;
  while not Terminated do begin
    if FInputBuffer.QueueSize > 0 then begin
      x:= FInputBuffer.PopItem;
      //some code to use x
    end;
  end;
  FInputBuffer.Free;
end;
Run Code Online (Sandbox Code Playgroud)

在其他课程:

var MyClass :TMyClass ;

procedure TForm1.btn1Click(Sender: TObject);
var x :TBytes;
begin
  //set x
  MyClass.FInputBuffer.PushItem(x);
end;
Run Code Online (Sandbox Code Playgroud)

delphi thread-safety delphi-xe2

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

"创建组合框"中的"控件没有父级"

在这段代码中:

unit MSEC;

interface

uses
  Winapi.Windows, Vcl.Dialogs, Vcl.ExtCtrls, System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls;

type
  TMSEC = class(TWinControl)
  private
    FOpr                  :TComboBox;
  public
    constructor Create(AOwner: TComponent); override;
  end;

implementation

const
    DEF_OPERATIONS :array[0..3] of Char = ('+', '-', '*', '/');

constructor TMSEC.Create(AOwner: TComponent);
var i         :Integer;
begin
  inherited;
  FOpr:= TComboBox.Create(Self);
  with FOpr do begin
    Parent:= Self;
    Align:= alLeft;
    Width:= DEF_OPERATIONS_WIDTH;
    Style:= csDropDownList;
    //error in next lines :
    Items.Clear;
    for i := Low(DEF_OPERATIONS) to High(DEF_OPERATIONS) do Items.Add(DEF_OPERATIONS[i]);
    ItemIndex:= 0;  
  end;
end;

end.
Run Code Online (Sandbox Code Playgroud)

当我更改ComboBox项目时,程序会中断消息:
'Control'没有父项.
如何修复此错误或以其他方式初始化ComboBox项?

delphi components combobox

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

标签 统计

delphi ×2

combobox ×1

components ×1

delphi-xe2 ×1

thread-safety ×1