如何在同一行中写入文字但颜色不同?(我使用richedit).
procedure TForm1.btnEClick(sender: TObject);
begin
m0.SelAttributes.Color := clBlue;
m0.SelAttributes.Style := [fsBold];
m0.lines.add('This is blue and it is bold');
m0.SelAttributes.Color := clGreen;
m0.SelAttributes.Style := [fsBold];
m0.lines.add ('This is Green and it is bold');
m0.lines.add('');
m0.lines.add('But how to write text in the same line with different color?');
// i want to have both blue and green in the same line
end;
Run Code Online (Sandbox Code Playgroud)
最好的祝福,蜜蜂
我想在进度条中放置一个标签.这个标签标题是动态的.如何将标签位置始终放在ProgressBar的中心位置?
我尝试过的;
Label1.Parent := progressBar1;
Label1Top := progressBar1.Height div 2;
Label1.Left := progressBar1.Width div 2
Run Code Online (Sandbox Code Playgroud)
它显示丑陋,而不是像我想要的那样处于中心位置.

如果我设置Label1.Left := progresBar1.Width div 2 - xxx它将只在某个标题的中心.我希望将任何标题放在中心位置.
来自@KenWhite的编辑答案工作得很好.来自@DavidHeffernan的解决方案很棒.

要确定我的exe路径,我不知道应该使用哪个代码.请给我解释我们何时以及为什么要使用:
1. ExtractFilePath(ParamStr(0))
2. ExtractFilePath(Application.ExeName)
因为两个代码都呈现相同的输出.
C:\Users\Bianca\Documents\RAD Studio\Projects\Exam1\Win32\Release\
C:\Users\Bianca\Documents\RAD Studio\Projects\Exam1\Win32\Release\
Run Code Online (Sandbox Code Playgroud) 我希望扫描计算机上存在的所有可用驱动器号,并获取详细信息(chk如果被占用,chk用于类型和大小).
关于如何使用下面的代码来获取大小,我没有任何问题
var
FreeAvail, totalSpace: Int64;
begin
if SysUtils.GetDiskFreeSpaceEx(PChar('F:\'), FreeAvail, totalSpace, nil) = True
then
begin
F1.Liner('Drive F total space ');
F1.pBold(IntToStr(totalSpace div (1024 * 1024 * 1024)) + ' GB ,');
F1.Liner(' available free space ');
F1.pBold(IntToStr(FreeAvail div (1024 * 1024 * 1024)) + ' GB.');
end;
end;
Run Code Online (Sandbox Code Playgroud)
但如果驱动器无人占用,我不喜欢这种情况.

问题:如何获得所有驱动器 - CDROM,USB棒等.更具体地说,我希望显示结果如下例所示;
驱动器E [本地磁盘] - TotalSpace 500 GB - FreeSpace 200 GB
驱动器F [CD驱动器] - 未占用 - FreeSpace 0
驱动器G [可移动] - TotalSpace 8 GB - FreeSpace 2 GB
我想限制一个TCheckListBox.我希望只检查2个项目,并且所有未检查的项目将被禁用并变灰.由于已选中/未选中的项目是动态的,因此我无法使用静态itemIndex.
这是我尝试过的,但我得到了"超出芯片范围"的错误.
在我的CheckListBox的click事件上;
var
NumberOfCheckedItems, I: Integer;
begin
NumberOfCheckedItems := 0;
for I := 0 to CkLst1.Count - 1 do
begin
if CkLst1.Checked[I] then
NumberOfCheckedItems := NumberOfCheckedItems + 1;
end;
if NumberOfCheckedItems > 1 then
begin
CkLst1.Checked[I] := Enabled;
CkLst1.Enabled := FALSE;
CkLst1.AllowGrayed := TRUE;
end
else
begin
//no idea
end;
end;
Run Code Online (Sandbox Code Playgroud) 如何查看 Windows 资源管理器是否已使用特定路径打开?我不希望我的应用程序打开许多重复的窗口。我无法通过这种方式做到这一点:
var
H: hwnd;
begin
if FileExists(edt8.Text) then
begin
H := FindWindow(0, PChar(ExtractFilePath(edt8.Text)));
if H <> 0 then
ShowMessage('explorer already opened')//explorer bring to front
else
ShellExecute(Application.Handle, nil, 'explorer.exe',
PChar(ExtractFilePath(edt8.Text)), nil, SW_NORMAL);
end;
end;
Run Code Online (Sandbox Code Playgroud) 这是关键的新闻事件:
procedure TForm3.Edt1KeyPress(Sender: TObject; var Key: Char);
begin
if not(Key in [#8, '0' .. '9']) then
begin
memo1.Clear;
Print('Numbers only !');
Key := #0;
end;
edt1.MaxLength := 12;
end;
Run Code Online (Sandbox Code Playgroud)
所以这是故事:
我想自动完成我的TEdit.每次我输入TEdit,它都会自动填写我的(任意)数字.只需在第一个数字后填入'0',它将被替换为第二个数字被输入...并停在最大长度(设置为12).
procedure TForm3.btn1Click(Sender: TObject);
var key : Char;
begin
if Trim(edt1.Text) = '' then
begin
memo1.Clear;
Print('Please input your number');
Exit
end;
// Text number CAN NOT LESS than 12 digits. I think it's better with auto-complete.
end;
Run Code Online (Sandbox Code Playgroud) 如何在此页面上进行转换? http://www.esnconverter.com/index.php?esn=88888888
我试图这样做,但结果是错误的
procedure TForm1.btn1Click(sender: TObject);
begin
memo1.Lines.Add (IntToStr(StrToInt('$'+Edit1.text)));
end;
Run Code Online (Sandbox Code Playgroud) 我想动态加载DLL函数。此函数在静态DLL模式下运行良好。但是我无法管理它在动态模式下工作。
type
TCallBackProcedure = procedure(StringValue: PAnsiChar;
IntegerValue: integer)stdcall;
type
TOpenPort = function(dnum: integer;
CallBackString: TCallBackProcedure): integer;
function xOpenPort(dnum: integer; CallBackString: TCallBackProcedure): integer;
const
tDLL = 'myDll.dll';
function OpenPort(dnum: integer; CallBackString: TCallBackProcedure): integer;
stdcall; external tDLL;
procedure CallBackString(StringValue: PAnsiChar; integerValue : Integer) stdcall;
begin
strAA := StringValue; // string
SLb.Add(strAA); // StringList
end;
Run Code Online (Sandbox Code Playgroud)
以静态模式运行没有问题。
iOutput := OpenPort(9, @CallBackString); // working fine
Run Code Online (Sandbox Code Playgroud)
这是我在动态负载下调用它的努力;
function xOpenPort(dnum: integer; CallBackString: TCallBackProcedure): integer;
var
hDll: THandle;
xOpen: TOpenPort;
begin
try
hDll := loadLibrary(tDLL);
if hDll <> …Run Code Online (Sandbox Code Playgroud) delphi ×10
checklistbox ×1
decimal ×1
delphi-xe ×1
dll ×1
drive-letter ×1
fonts ×1
label ×1
path ×1
progress-bar ×1
richedit ×1