我有一组文件:
001.txt
001a.txt
002.txt
002a.txt
...
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下代码来排除以 结尾的项目a,例如001a.txt
PROCEDURE TForm1.FindFiles(StartDir, FileMask: STRING);
VAR
sr: TSearchRec;
IsFound: Boolean;
BEGIN
IsFound := FindFirst(StartDir + FileMask, faAnyFile - faDirectory, sr) = 0;
WHILE IsFound DO
BEGIN
if sr.Name <> '*a.*' then
gFiles.add(StartDir + sr.Name);
IsFound := FindNext(sr) = 0;
END;
FindClose(sr);
END;
Run Code Online (Sandbox Code Playgroud)
该FileMask传递给该过程之中是'*.*'包括所有文件。
但是,以上返回所有文件。
所以我的问题是如何从搜索中排除这些文件?
我有一个程序n ComboBoxes和n Labels,我想更新相应的Label根据来自相邻的选择ComboBox,即ComboBox2会更新Label2。
我为每个ComboBox当前检查是否Combobox1或Combobox2已经触发事件处理程序使用相同的事件处理程序。有没有办法使用的一种方式ItemIndex的ComboBox传递到过程,如Sender.ItemIndex?这目前不是一个选项,并给出了错误'TObject' does not contain a member named 'ItemIndex'。
procedure TForm2.ComboBoxChange(Sender: TObject);
begin
if Sender = ComboBox1 then
Label1.Caption := ComboBox1.Items.Strings[ComboBox1.ItemIndex]
else
Label2.Caption := ComboBox2.Items.Strings[ComboBox2.ItemIndex];
end;
Run Code Online (Sandbox Code Playgroud)
此代码具有所需的行为,但显然不可扩展。
我创建了一个类:
type
TShape = class
private
FHeight: Integer;
FWidth: Integer;
FDepth: Integer;
public
constructor CreateShape(AHeight: Integer; AWidth: Integer; ADepth: Integer);
property height: Integer index 0 read FHeight write FHeight;
property width: Integer index 1 read FWidth write FWidth;
property depth: Integer index 2 read FDepth write FDepth;
end;
Run Code Online (Sandbox Code Playgroud)
.
constructor TShape.CreateShape(AHeight: Integer; AWidth: Integer;
ADepth: Integer);
begin
inherited Create;
FHeight := AHeight;
FWidth := AWidth;
FDepth := ADepth;
end;
Run Code Online (Sandbox Code Playgroud)
目前我通过使用属性名称分配变量来分配值:
cube := TShape.CreateShape(5, 5, 5);
height1 := cube.FHeight;
width1 := …Run Code Online (Sandbox Code Playgroud) 我正在显示带有 Yes 和 No 按钮的 messageDlg 确认屏幕。反转代码中的按钮没有任何影响。
answer := messageDlg('Are you sure?', mtConfirmation, [mbYes, mbNO], 0);
Run Code Online (Sandbox Code Playgroud)
有没有办法在不创建自定义对话框的情况下将默认选项更改为否,例如此处演示的Delphi 中显示自定义消息对话框的最佳方法是什么?