使用Delphi 7,我需要将所有内容(文件,文件夹和子文件夹)从一个文件夹移动到另一个文件夹.经过一些研究,SHFileOpStruct似乎是最好的选择.这是我到目前为止所得到的:
function MoveDir(SrcDir, DstDir: string): Boolean;
var
FOS: TSHFileOpStruct;
begin
ZeroMemory(@FOS, SizeOf(FOS));
with FOS do
begin
wFunc := FO_MOVE; // FO_COPY;
fFlags := FOF_FILESONLY or
FOF_ALLOWUNDO or FOF_SIMPLEPROGRESS;
pFrom := PChar(SrcDir + #0);
pTo := PChar(DstDir + #0);
end;
Result := (SHFileOperation(FOS) = 0);
end;
Run Code Online (Sandbox Code Playgroud)
但是当使用此功能时,整个文件夹将移动到目标,而不仅仅是内容.例如,如果我使用MoveDir('c:\ test','d:\ test'),我会得到d:\ teste\teste.
我已经尝试改变这条线了,它在处理文件(FO_COPY)时起作用,但在移动时不起作用.
pFrom := PChar(SrcDir + '\*.*' + #0);
Run Code Online (Sandbox Code Playgroud)
拜托,有人可以帮我吗?如果我能在不逐个文件夹的情况下移动文件夹,那就太棒了...
谢谢!!
我有一个带有TabControl组件的Delphi VCL表单应用程序(用于Windows),其中选项卡在运行时创建.Imagesproperty链接到ImageList,我使用OnGetImageIndex事件根据状态信息为每个选项卡设置图像索引.在某些时候,当状态改变时,我需要更新这个图像(索引).我的第一个想法是致电:
TabControl1.Invalidate;
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我也尝试了另一种没有成功的方法:
TabControl1.Repaint;
RedrawWindow(TabControl1.Handle, nil, 0, RDW_ERASE or
RDW_INVALIDATE or RDW_ALLCHILDREN);
Run Code Online (Sandbox Code Playgroud)
请问,我如何为每个标签强制使用OnGetImageIndex?谢谢!
我最近开始使用Indy 10(来自Delphi XE3)和TCP连接.目前,我正在尝试创建一个简单的服务器应用程序来检查客户端状态.但是当我尝试在某些客户端已连接的情况下停用TCPServer时,客户端会断开连接,但TCPServer会停止应答.
我在某处读到TCPServer应该没有问题地处理客户端的断开连接.我必须在OnExecute事件上添加一些代码来解决这个问题吗?
这是代码:
procedure TfrmMain.btnConnectClick(Sender: TObject);
begin
If (not TCPServer.Active) Then
Try
TCPServer.Bindings.Clear;
With TCPServer.Bindings.Add Do
Begin
IP := '192.168.1.11';
Port := StrToInt(edtPort.Text);
end;
TCPServer.Active := True;
Except
On E:Exception Do ShowMessage(E.Message);
End
end;
procedure TfrmMain.btnDisconnectClick(Sender: TObject);
begin
If (TCPServer.Active) Then
Try
TCPServer.Active := False;
Except
On E:Exception Do ShowMessage(E.Message);
End
end;
procedure TfrmMain.TCPServerConnect(AContext: TIdContext);
var
IdStackWin: TIdStackWindows;
begin
IdStackWin := TIdStackWindows.Create;
With IdStackWin Do
Try
memLog.Lines.Add('Connected - ' + HostByAddress(AContext.Binding.PeerIP) + ' (' + AContext.Binding.PeerIP + ')'); …Run Code Online (Sandbox Code Playgroud) 我需要从IdTCPServer向特定连接的IdTCPClient发送一个字符串消息.一开始我使用的是Listbox,所以我在连接客户端时将主机名添加到列表框中,并在断开连接时删除.那时,Remy Lebeau给我这个提示:
procedure TfrmMain.sendButtonClick(Sender: TObject);
var
Index: Integer;
Ctx: TIdContext;
begin
Index := ListBox.ItemIndex;
if Index = -1 then Exit;
Context := TIdContext(ListBox.Items.Objects[Index]);
// use Context as needed...
end;
Run Code Online (Sandbox Code Playgroud)
但现在我正在使用Listview,预先添加了主机名.所以我只是在客户端连接或断开连接时更改列表框项目图像状态.现在我正在尝试这样的事情:
procedure TfrmMain.TCPServerConnect(AContext: TIdContext);
begin
TThread.Queue(nil,
procedure
var
Host: String;
LItem: TListItem;
begin
Host := UpperCase(GStack.HostByAddress(Ctxt.Binding.PeerIP));
LItem := lvwPCList.FindCaption(0, Host, False, True, False);
if (LItem <> nil) then LItem.Data := AContext.Data;
end
);
end;
Run Code Online (Sandbox Code Playgroud)
一旦我将Listview项与Context数据相关联,我就试图将消息直接发送给客户端:
procedure TfrmMain.SendMessage(const Item: TListItem; const Msg: String);
var
Ctx: TIdContext;
begin
if (Trim(Msg) = '') then …Run Code Online (Sandbox Code Playgroud) 根据我对此主题的有限知识,以下代码应该有效.但我没有预期的结果:
type
TClient = class(TObject)
Host: String;
end;
var
Clients: TThreadList;
const
Hosts: Array[0..5] of String = ('HOST1', 'HOST2', 'HOST3', 'HOST4', 'HOST5', 'HOST6');
var
I: Integer;
List: TList;
Client: TClient;
begin
try
for I := Low(Hosts) to High(Hosts) do
begin
Client := TClient.Create;
with Client Do
try
Host := Hosts[I];
List := Clients.LockList;
try
Clients.Add(Client);
finally
Clients.UnlockList;
end;
finally
Client.Free;
end;
end;
except
on E:Exception Do ShowMessage(E.Message);
end;
// RESULT TEST
List := Clients.LockList;
try
I := List.Count;
S := …Run Code Online (Sandbox Code Playgroud) 我有2个简单的表单,Form1和Form2(Delphi 7).Form1打开Form2,然后我等待特定的组合键(Ctrl + F2).一旦我关闭Form2并返回到Form1,我需要检查是否按下了Ctrl键.这是一个例子:
FORM2
procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Shift = [ssCtrl]) and (Key = VK_F2) then
ShowMessage('Ctrl + F2 pressed!');
end;
Run Code Online (Sandbox Code Playgroud)
FORM1
procedure TForm1.btn1Click(Sender: TObject);
begin
Try
Application.CreateForm(TForm2, Form2);
Form2.ShowModal;
Finally
Form2.Release;
Form2 := nil;
end;
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
if (GetAsyncKeyState(VK_Control) <> 0) then
ShowMessage('Ctrl is pressed!');
end;
Run Code Online (Sandbox Code Playgroud)
问题是,每次我在Form2上按Ctrl + F2时,似乎Ctrl键卡住了,(GetAsyncKeyState(VK_Control)<> 0)总是返回true.
请问,你知道发生了什么(以及如何解决)?
我在某些地方提到了一些有关这方面的理论信息,但我还不明白......
让我知道我有这个功能和程序:
function ProcessVars1(var param1: type1; var param2: type2; var param3: type3): Boolean;
function ProcessVars2(var param1: type1; var param2: type2; var param3: type3): Boolean;
function ProcessVars3(var param1: type1; var param2: type2; var param3: type3): Boolean;
function ProcessVarsX(var param1: type1; var param2: type2; var param3: type3): Boolean;
function ProcessVars(const x: Integer; var param1: type1; var param2: type2; var param3: type3): Boolean;
var
Res: Boolean;
begin
case x of
1: Res := ProcessVars1(param1, param2, param3);
2: Res := ProcessVars2(param1, param2, param3);
3: …Run Code Online (Sandbox Code Playgroud) 我正在使用 Delphi 7 并尝试在运行时创建一个WebBrowserinside a Form,但无法使其工作。这是代码:
procedure TForm1.Button1Click(Sender: TObject);
var
Form: TForm;
Brws: TWebBrowser;
begin
Form := TForm.Create(nil);
try
Form.Width := 500;
Form.Height := 500;
Form.BorderStyle := bsDialog;
Form.Position := poScreenCenter;
Form.Caption := 'Select the Option';
Brws := TWebBrowser.Create(Form);
Brws.ParentWindow := Form.Handle;
TWinControl(Brws).Parent := Form;
Brws.Align := alClient;
Brws.AddressBar := False;
Brws.MenuBar := False;
Brws.StatusBar := False;
Application.ProcessMessages;
if Form.ShowModal = mrOk then
Brws.Navigate('https://www.google.com');
finally
Form.Free;
end;
end;
Run Code Online (Sandbox Code Playgroud)
结果就像 WebBrowser 没有响应。我有一个白屏,没有错误消息。
请问,我错过了什么?谢谢!
我使用Windows 64位与UAC,需要检查Windows系统文件夹中是否存在文件,而不提升权限.已经在过去6小时内搜索解决方案,但没有成功...... :(
根据这个问题,FileExists()返回false,即使文件存在,我也可以使用Wow64DisableWow64FsRedirection(),但我在许多其他地方看到它不推荐.
现在我正在尝试使用特殊的"Sysnative"别名,但是当使用FileExists功能时,它不起作用(例如:如果fileexists('C:\ Windows\Sysnative\dfrgui.exe')则...)
拜托,有人可以帮我吗?也许是汇编(Asm)解决方案?
谢谢!
我SHGetSpecialFolderPath用Delphi 7检索一些Windows特殊文件夹.这是一些代码示例:
const
CSIDL_DESKTOP = $0000;
CSIDL_PERSONAL = $0005;
CSIDL_MYPICTURES = $0027;
CSIDL_MYMUSIC = $000d;
CSIDL_MYVIDEO = $000e;
CSIDL_WINDOWS = $0024;
CSIDL_SYSTEM = $0025;
function GetSpecialFolderPath(Folder: Integer; ForceDir: Boolean): string;
// Uses ShlObj
var
Path: array [0..255] of char;
begin
SHGetSpecialFolderPath(0, @Path[0], Folder, ForceDir);
Result := Path;
end;
edtFolder.Text := GetSpecialFolderPath(CSIDL_DESKTOP, False);
Run Code Online (Sandbox Code Playgroud)
如何使用此方法获取"下载"文件夹?
出于某些原因,我需要有这样的东西:
DT: array[0..3] of types = (string, integer, double, boolean);
Run Code Online (Sandbox Code Playgroud)
这甚至可能吗?