在 VCL (Delphi 2010) 中,我使用这个函数来检查是否按下了控制键:
function IsControlKeyPressed: Boolean;
begin
Result := GetKeyState(VK_CONTROL) < 0;
end;
Run Code Online (Sandbox Code Playgroud)
GetKeyState 是 Windows 库中的函数,我不想将它包含在我的项目中。
如何检查是否在 XE3 中为 firemonkey 应用程序按下了 control 或 shift 键?
如何将字符串hex转换为int 8的数组?
var hash : string;
x: array[0..19] of int8;
begin
hash := '713BD6D36D4964F4E4F843CB03D118EA5C372FF6';
put_hash_into_x(hash);
end;
Run Code Online (Sandbox Code Playgroud)
谢谢
我尝试使用 Delphi XE3 插入 SQLite 中的 blob 字段。
我一直像这样使用 TDBXCommand 和 TSQLConnection 。但 blob 字段未插入,甚至我无法从查询中获得任何结果
procedure TDBXCommandHelper.Init(const AQry: String);
begin
Parameters.ClearParameters;
Close;
Prepare;
Text := AQry;
end;
procedure dmDB.InsertPicture;
const
QRY = 'INSERT INTO Memo(Picture) VALUES(?)';
var
LTransaction: TDBXTransaction;
LBlob: TDBXParameter;
LStream: TFileStream;
begin
LTransaction := FDBCon.BeginTransaction;
LStream := TFileStream.Create('d:\sample.bmp', fmOpenRead);
LBlob := TDBXParameter.Create;
try
try
FDBXCmd := FDBCon.DBXConnection.CreateCommand;
FDBXCmd.CommandType := TDBXCommandTypes.DbxSQL;
FDBXCmd.Init(QRY);
LBlob.DataType := TDBXDataTypes.BlobType;
LBlob.SubType := TDBXSubDataTypes.BinarySubType;
LBlob.Value.SetStream(LStream, False);
FDBXCmd.Parameters.AddParameter(LBlob);
FDBXCmd.ExecuteUpdate;
except
on E: Exception do
FDBCon.RollbackFreeAndNil(LTransaction);
end; …Run Code Online (Sandbox Code Playgroud) 从抽象Base类创建子类的最佳方法.
在我的项目中,我有一个基类抽象和两个子类.
TbaseClass=class
public
procedure Doit;virtual;abstract;
procedure Calculate;virtual;abstract;
Tchild1class=class(TbaseClass)
..
protected
procedure CalcArea;virtual;
public
procedure Doit;override;
procedure Calculate;override;
Tchild2class=class(Tchild1class)
protected
procedure CalcArea;override;
Run Code Online (Sandbox Code Playgroud)
在我的buttonclick代码中,我以这种方式创建了所需的子类,并且正在工作.
.....
var
T:TBaseClass;
begin
case OP of
1: T:=Tchild1class.Create;
2: T:=TChild2Class.Create;
T.Doit;
T.Calculate;
end;
Run Code Online (Sandbox Code Playgroud)
我的问题是下一个.我可以在我的基本抽象类中创建一个构造函数创建过程,这取决于int参数生成所需的子类??? 例如:
constructor TBaseClass.Create(OP:integer);
begin
inherited;
case OP of
1: Tchild1class.Create; ///>>>???
2: TChild2Class.Create; //>>>>???
end;
Run Code Online (Sandbox Code Playgroud)
这可能吗?
这样做的最佳方法是什么?
我有这个功能,如果我使用GetIP('server-name')或GetIP('google.com')在我的Delphi 2006 中检索IP地址.
但现在我正在尝试它,Delphi-XE3它不起作用.有任何想法吗?
function GetIP(const HostName: string): string;
var
WSAData: TWSAData;
R: PHostEnt;
A: TInAddr;
begin
Result := IPNULL; // '0.0.0.0'
WSAStartup($101, WSAData);
R := Winsock.GetHostByName(PAnsiChar(HostName));
if Assigned(R) then
begin
A := PInAddr(r^.h_Addr_List^)^;
Result := string(WinSock.inet_ntoa(A));
end;
end;
Run Code Online (Sandbox Code Playgroud)
似乎R没有被分配,因为结果总是如此'0.0.0.0'
在我的项目中,我需要使用正则表达式在400mb TMemoryStream对象中查找一些数据.我在delphi xe3中检查新的regularrexpresion,但函数只与接收到的字符串参数匹配,而不是rawbytestring或pointer.我通过这种方式定义了模式:
MyPatt:="\x8A\x8A(..)\x8A"
Run Code Online (Sandbox Code Playgroud)
问题是如何找到我试过的二进制rawdata里面
TRegex.Match((MyStreamObject.Memory)^,MyPatt);
Run Code Online (Sandbox Code Playgroud)
但没有成功.我试着用这个而不是成功
TRegex.Match(String((MyStreamObject.Memory)^),MyPatt);
Run Code Online (Sandbox Code Playgroud)
bcz问题是如果rawbinary对象以0x00开头被截断.
我如何使用指针或rawbinarystring匹配正则表达式.
procedure TForm1.UDPUDPRead(AThread: TIdUDPListenerThread;
AData: array of Byte; ABinding: TIdSocketHandle);
var
buffer : TBytes;
begin
SetLength(buffer, Length(AData));
buffer := @AData[0];
end;
Run Code Online (Sandbox Code Playgroud)
此代码导致访问冲突。
什么是要转换的正确方法字节数组以TB的在Delphi XE3?
我在其中一个项目中遇到了一些奇怪的问题.最奇怪的是,这只发生在这个项目中,我无法在另一个项目中重新创建它.
Luckilly这是一个很小的项目(旨在为SO提供一个问题的答案 - 仍然没有完成)所以我设法弄清楚它必须做什么来破坏我在设计上放置在我的表单上的TImage组件时间并在设计时也为其设置BMP图像.
我得到的AV是:项目Project1.exe引发异常类$ C0000005,消息'访问冲突在0x00407430:读取地址0xfffffffc'.
最后三个调用堆栈是:
Vcl.Graphics.TBitmapCanvas.Destroy
Vcl.Graphics.TCanvasDestroy
System.TObject.Free
此外,Delphi将我置于"Destroy"行的TObbject.Free方法中的System.pas单元中.
procedure TObject.Free;
begin
if Self <> nil then
{$IFDEF AUTOREFCOUNT}
__ObjRelease;
{$ELSE}
Destroy;
{$ENDIF}
end;
Run Code Online (Sandbox Code Playgroud)
此时Self的值仅显示为().
但是为什么只有在我将一些数据存储到我的多维数组中时才会发生这种AV.
我可以在运行时创建和设置多维数组的大小,每一个都很好.但是一旦我更改了这个多维数组中某些项的数据,我就会在关闭应用程序时获得AV.
这是我的完整源代码:
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TSubImage = record
LeftBound: Integer;
RightBound: Integer;
TopBound: Integer;
BottomBound: Integer;
end;
TForm2 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations } …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我们的系统制作一个小工具,以防止我们的软件运行时 Windows 关闭。为了使其独立,我制作了一个单独的应用程序来防止使用此信息关闭。
然而,当应用程序最小化到托盘时,Windows 会简单地杀死它并正常关闭。如果表单可见(又名我注释 Form.OnCreate 事件中的 Application.Minimize 调用),它确实会阻止正常关闭。
我如何实现 MainWindow 挂钩以保持活动状态,或者通过其他方式防止系统关闭,并将应用程序隐藏在托盘中?
谢谢。
当前代码:
unit Main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, TlHelp32, dateutils, Vcl.AppEvnts, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
TrayIcon1: TTrayIcon;
ApplicationEvents1: TApplicationEvents;
procedure FormCreate(Sender: TObject);
function HookEndSession(var Message: TMessage): Boolean;
procedure WMQueryEndSession(var Msg : TWMQueryEndSession) ;
message WM_QueryEndSession;
procedure ApplicationEvents1Minimize(Sender: TObject);
procedure ApplicationEvents1Restore(Sender: TObject);
procedure TrayIcon1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var Form1: TForm1; …Run Code Online (Sandbox Code Playgroud) 我正在使用 Delphi XE3。
在我的代码中,我需要创建一个文件流,然后将一些我自己的数据,以及几个TStringList的内容写入其中。该文件采用 UTF-16LE 格式。
因此,我的代码:
FileStream := TFileStream.Create('D:\MyFile.dat', fmCreate or fmOpenWrite or fmShareExclusive);
try
// Write some data to FileStream
// Write contents of StringList1 into FileStream
StringList1.SaveToStream(FileStream, TEncoding.Unicode);
// Write some more data to FileStream
// Write contents of StringList2 into FileSteram
StringList2.SaveToStream(FileStream, TEncoding.Unicode);
finally
FileStream.Free;
end;
Run Code Online (Sandbox Code Playgroud)
执行完代码,发现一个问题,每次调用StringList1.SaveToStream(FileStream, TEncoding.Unicode); 它将写入 BOM (0xFFFE),然后是字符串列表中的实际字符串。
因此,我得到一个这样的 Unicode 文件:
0xFFFE(第一个是我自己写的)
(一些数据)
0xFFFE(StringList1 内容)
(一些数据)
0xFFFE(StringList2 内容)
但这不是我所期望的,因为文件开头应该只有一个 0xFFFE。因此,我只是想知道如何在写入实际字符串列表之前防止 StringList1.SaveToStream 写入 0xFFFE BOM?
delphi ×10
delphi-xe3 ×10
casting ×1
dns ×1
firemonkey ×1
ip ×1
keyboard ×1
polymorphism ×1
regex ×1
sqlite ×1
tstringlist ×1
udp ×1