我正在使用 Delphi 应用程序。我创建了一个如下所示的表单:

我想通过代码从这个控件中制作组件。但是不能通过组件-->创建组件模板-->等等。
如何通过delphi代码使组件模板脱离表单控制。??提前谢谢。
是否有方法或编译器指令或某种方式来确保某些组件(例如查询或数据库连接)在运行构建/编译时设置为 active=false 或断开连接?这些似乎经常被其他东西打开,直到为时已晚你才注意到它。
我的特定安装是 Delphi 7
当我以编程方式导致下拉选择列表出现时,我无法弄清楚为什么我无法手动滚动TComboBox组件.这是我正在使用的代码:
SendMessage(ComboBox1.handle, CB_SHOWDROPDOWN, Integer(True), 0);
Run Code Online (Sandbox Code Playgroud)
这会导致下拉选择列表出现.但是,如果我尝试使用键盘并使用向上和向下箭头键,则下拉选择列表会立即关闭.使用键盘上/下导航键时如何防止列表自动关闭?
EoF首次进入while循环时,该程序会引发I/O 104错误.
该程序的目的是查找是否已经使用了用户名.现有用户名存储在文本文件中.
procedure TForm1.btnRegisterClick(Sender: TObject);
begin
sCUser := edtUserName.Text;
AssignFile(tNames, 'Names.txt');
begin
try
Reset(tNames);
except
ShowMessage('File not found');
Exit;
end;
end;
rewrite(tNames);
while not EoF(tNames) do // I get a I/O 104 Error here `
begin
Readln(tNames, sLine);
iPosComme := Pos(',', sLine);
sUser := Copy(sLine, 1, iPosComme - 1);
Delete(sLine, 1, iPosComme - 1);
if sCUser = sUser then begin
ShowMessage('Username taken');
end
else
begin
rewrite(tNames);
Writeln(tNames, sCUser + ',' + '0');
CloseFile(tNames);
end;
end;
end;
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 delphi 创建一个 dll,我设置了一些文件属性,但随后我想从工作目录运行一个 .exe 文件。我尝试使用此代码运行 exe 文件
ShellExecute(Handle, 'open', 'start.exe', nil, nil, SW_SHOWNORMAL);
Run Code Online (Sandbox Code Playgroud)
但我收到错误:未声明的标识符“句柄”。
未声明的标识符“SW_SHOWNORMAL”
运行 exe 文件的最佳方法是什么?
如何将特定文件夹和子文件夹中的文件只能在delphi中读取?我知道我可以将FileSetAttr的文件夹设置为只读,但有没有办法从文件夹和子文件夹中放入文件?
谢谢
我正在使用Delphi 7.我想更改messageDlg宽度.
我的意思是我的消息测试很长,因为该消息显示在2行,但我想只在一行显示消息.
下面是我的单行代码
MessageDlg('i want to display only in oneline i want to display only in oneline i want to display only in oneline i want to display only in oneline i want to display only in oneline',mtError,[mbok],0)
Run Code Online (Sandbox Code Playgroud)
上面的消息显示在2行,但我想只在一行显示消息.
我有这个功能:
var
_WordApplicationExistsCache: Integer = -1; // Cache result
function WordApplicationExists: Boolean;
var
WordObj: OleVariant;
begin
if (_WordApplicationExistsCache = -1) then
begin
Result := False;
try
try
WordObj := CreateOleObject('Word.Application');
WordObj.Visible := False;
WordObj.Quit;
WordObj := Unassigned;
Result := True;
except
// error
end;
finally
_WordApplicationExistsCache := Ord(Result); // 0;1
end;
end
else
begin
Result := Boolean(_WordApplicationExistsCache);
end;
end;
Run Code Online (Sandbox Code Playgroud)
我试图在应用程序生命周期中只调用一次此函数.我可能根本不会调用这个函数.
这是正确的模式吗?这可以做得更好吗?
编辑:我能想到的另一种方式,在这种情况下是使用2个变量:
var
_WordApplicationExistsInitialized: Boolean = False; // Cache result
_WordApplicationExistsCacheResult: Boolean; // Undefined ?
function WordApplicationExists: Boolean;
var
WordObj: …Run Code Online (Sandbox Code Playgroud) 我试图在Delphi和PHP之间交换加密的消息.
从Delphi方面我从这里下载了DCPcrypt v2 Beta 3:
http://www.cityinthesky.co.uk/opensource/dcpcrypt/
对于加密我使用此功能:
function TForm1.Encrypt3DES(psData, psKey: string): string;
var
Cipher: TDCP_3des;
begin
Cipher:= TDCP_3des.Create(nil);
Cipher.InitStr(psKey,TDCP_sha256);
result:=Cipher.EncryptString(psData);
Cipher.Burn;
Cipher.Free;
end;
Run Code Online (Sandbox Code Playgroud)
我正在测试它:
ShowMessage(Encrypt3DES('test','SecretKeySecretKeySecret'));
Run Code Online (Sandbox Code Playgroud)
我得到的结果是Z74E0Q ==我可以使用另一个类似的delphi函数成功解密它:
function TForm1.Decrypt3DES(psData, psKey: string): string;
var
Cipher: TDCP_3des;
begin
Cipher:= TDCP_3des.Create(nil);
Cipher.InitStr(psKey, TDCP_sha256);
result:=Cipher.DecryptString(psData);
Cipher.Burn;
Cipher.Free;
end;
Run Code Online (Sandbox Code Playgroud)
从PHP端我试过几个功能相同的字符串("测试")使用相同的密钥("SecretKeySecretKeySecret")加密,但结果是什么,我在Delphi中得到不同的.我再次成功解密PHP中具有类似功能的消息,但我需要在Delphi中解密消息.
这是我在PHP中所做的,我甚至试图散列键,因为我看到Delphi函数正在使用TDCP_sha256,但结果仍然不同.
$key = "SecretKeySecretKeySecret";
echo base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, 'test', 'ecb')).'<BR><BR>';
echo openssl_encrypt('test', 'des-ede3', $key).'<BR><BR>';
$key = hash('sha256', $key);
echo openssl_encrypt('test', 'des-ede3', $key).'<BR><BR>';
Run Code Online (Sandbox Code Playgroud)
这是结果:
Z05z5Bp4/VY =
L5qmk5nJOzs =
bm7yRdrMs5g =
我究竟做错了什么?BTW我正在使用Delphi 7和DCPcrypt是目前唯一能够让它运行的库.