在XE5中所有条件编译如
{$IFDEF MSWINDOWS}
Run Code Online (Sandbox Code Playgroud)
被替换为
{$IF defined(MSWINDOWS)}
Run Code Online (Sandbox Code Playgroud)
例如XE4中的System.Diagnostics.pas
...
implementation
{$IFDEF MSWINDOWS}
uses Winapi.Windows;
{$ENDIF}
{$IFDEF MACOS}
uses Macapi.Mach;
{$ENDIF}
{ TStopwatch }
...
Run Code Online (Sandbox Code Playgroud)
现在在XE5中它看起来像:
...
implementation
{$IF defined(MSWINDOWS)}
uses Winapi.Windows;
{$ELSEIF defined(MACOS)}
uses Macapi.Mach;
{$ELSEIF defined(POSIX)}
uses Posix.Time;
{$ENDIF}
{ TStopwatch }
...
Run Code Online (Sandbox Code Playgroud)
是否有任何特殊原因我应该迁移我的类似调用?
delphi conditional-compilation defined conditional-statements delphi-xe5
我想在XE5中这样做:
type
TMyRec = record
// fields
class function GetList: TMyRecArr; static;
end;
TMyRecArr = array of TMyRec;
Run Code Online (Sandbox Code Playgroud)
我已经看过"记录类型的前向声明"和"如何进行类型转发声明?" ,但它们似乎无关紧要,因为我的问题是没有将记录作为参数传递.
我创建了这个"线程安全"的通用属性,我可以在主线程和后台线程之间使用.我之所以这样做是因为我厌倦了为所有属性和变量创建锁定对象.
TLockedProp<MyType> = class
private
FMyProp:MyType;
PropLock:TObject;
procedure SetMyProp(const Value: MyType);
function GetMyProp: MyType;
published
property Value:MyType read GetMyProp write SetMyProp;
public
Constructor Create;
Destructor Destroy;override;
end;
{ TLockedProp<MyType> }
constructor TLockedProp<MyType>.Create;
begin
inherited;
PropLock:=TObject.create
end;
destructor TLockedProp<MyType>.Destroy;
begin
PropLock.Free;
inherited;
end;
function TLockedProp<MyType>.GetMyProp: MyType;
begin
TMonitor.Enter(PropLock);
result := FMyProp;
TMonitor.Exit(PropLock);
end;
procedure TLockedProp<MyType>.SetMyProp(const Value: MyType);
begin
TMonitor.Enter(PropLock);
FMyProp := Value;
TMonitor.Exit(PropLock);
end;
Run Code Online (Sandbox Code Playgroud)
我有什么问题可以忽略吗?这是使用此属性类的一些代码.告诉我你的想法.
TBgThread=class(TThread)
private
FPaused: TLockedProp<boolean>;
FCount:TLockedProp<integer>;
procedure ChangeCount(pPlusMin:integer);
function GetPaused:boolean;
function GetCount:integer;
public
constructor Create;
destructor Destroy;override; …Run Code Online (Sandbox Code Playgroud) 4I必须将字符串写入二进制MIDI文件.该标准要求人们知道字符串的长度(以字节为单位).因为我想为移动设备写作,所以我不能使用AnsiString,这是确保字符串是一个单字节字符串的好方法.这简化了事情.我测试了以下代码:
TByte = array of Byte;
function TForm3.convertSB (arg: string): TByte;
var
i: Int32;
begin
Label1.Text := (SizeOf (Char));
for i := Low (arg) to High (arg) do
begin
label1.Text := label1.Text + ' ' + IntToStr (Ord (arg [i]));
end;
end; // convert SB //
convertSB ('MThd');
Run Code Online (Sandbox Code Playgroud)
它在Windows和Android中返回2 77 84 104 100(作为标签文本).这是否意味着Delphi默认将字符串视为UTF-8?这将大大简化一些事情,但我无法在帮助中找到它.将此转换为字节数组的最佳方法是什么?读取每个字符并测试它是1,2或4字节并在数组中分配此空间?要转换回字符:只读取字节数,直到遇到一个字节<128?
在Delphi的对象检查器中,我在属性名称(ConnectionName*)后面看到一个星号:

它是如何实现的,最重要的是:它是什么意思?
在TMySQLConnection的源代码中,我没有看到任何特别的东西,所以我想这是一些设计时间的事情?
更新
它与TSQLConnection的内容有关.
要重现,请将下面的代码粘贴到表单上.
经过一些游戏后,我得出结论,当Params属性被编辑时,星号会出现,因此它不再具有默认值.对我来说,如何实现这一目标仍然是个谜.
object SQLConnection1: TSQLConnection
ConnectionName = 'MySQLConnection'
DriverName = 'MySQL'
LoginPrompt = False
Params.Strings = (
'DriverUnit=Data.DBXMySQL'
'DriverPackageLoader=TDBXDynalinkDriverLoader,DbxCommonDriver190.' +
'bpl'
'DriverAssemblyLoader=Borland.Data.TDBXDynalinkDriverLoader,Borla' +
'nd.Data.DbxCommonDriver,Version=19.0.0.0,Culture=neutral,PublicK' +
'eyToken=91d62ebb5b0d1b1b'
'MetaDataPackageLoader=TDBXMySqlMetaDataCommandFactory,DbxMySQLDr' +
'iver190.bpl'
'MetaDataAssemblyLoader=Borland.Data.TDBXMySqlMetaDataCommandFact' +
'ory,Borland.Data.DbxMySQLDriver,Version=19.0.0.0,Culture=neutral' +
',PublicKeyToken=91d62ebb5b0d1b1b'
'GetDriverFunc=getSQLDriverMYSQL'
'LibraryName=dbxmys.dll'
'LibraryNameOsx=libsqlmys.dylib'
'VendorLib=LIBMYSQL.dll'
'VendorLibWin64=libmysql.dll'
'VendorLibOsx=libmysqlclient.dylib'
'MaxBlobSize=-1'
'DriverName=MySQL'
'HostName='
'Database='
'User_Name=xxx'
'Password='
'ServerCharSet='
'BlobSize=-1'
'ErrorResourceFile='
'LocaleCode=0000'
'Compressed=True'
'Encrypted=False'
'ConnectTimeout=60')
Left = 48
Top = 24
end
Run Code Online (Sandbox Code Playgroud) 我正在使用Delphi XE5开发一个Android应用程序,我想知道如何在默认浏览器中打开一个URL,以及一个带有默认阅读器的PDF文件.我用过Windows开发ShellExecute,但对于Android和iOS,我应该使用什么?
我有一个名为VR的Delphi项目,它生成一个名为VR.exe的可执行文件.令我沮丧的是,我发现Windows(我正在运行Window 7 64位Ultimate)添加了开始菜单和游戏下的链接:搜索和救援:越南MED + EVAC.链接的图标是默认的delphi应用程序图标.
做了一些研究,我找到了这篇文章:
如何阻止Windows执行此操作?
更新:我有另一个项目MM,它生成mm.exe.这个创建了Steam Dark Messiah Might和Magic Single Player的链接.
另一个更新:我们向Microsoft提交了支持请求.他们承认这是一个错误,然而,他们未能提供修复的时间表.
更新:这是微软的答案:
我写信通知你,这个问题在我们的最后是可以重现的,我们也在过去报道了这个问题.由于这已经被我们的代码确定为"按设计",并且到目前为止我们没有对此进行解决,因此我无法提供帮助.但是,如果您有任何想要了解的信息,例如它如何影响业务或任何其他问题,请告诉我.
我接受了雷米的回答.
我意识到Delphi不支持接口助手,但在阅读了几个SO主题和Spring4D的来源之后,我想知道有没有办法实现以下目的?源代码评论几乎总结了我正在尝试做的事情,所以这里是:
program IHelper;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Spring,
System.SysUtils;
type
IMyThing = interface
['{01E799A5-9141-4C5E-AA85-B7C9792024D9}']
procedure BasicThing;
end;
TMyThing = class(TInterfacedObject, IMyThing)
strict private
procedure BasicThing;
end;
IMyThingHelper = record
private
FOutage: IMyThing;
public
class operator Implicit(const Value: IMyThing): IMyThingHelper;
procedure HelpfulThing;
end;
TMyThingHelper = class helper for TMyThing
public
class procedure ObjectThing;
end;
{ TOutage }
procedure TMyThing.BasicThing;
begin
Writeln('Basic Thing');
end;
{ IOutageHelper }
procedure IMyThingHelper.HelpfulThing;
begin
Writeln('Helpful thing');
end;
class operator IMyThingHelper.Implicit(const Value: IMyThing): IMyThingHelper;
begin
Result.FOutage …Run Code Online (Sandbox Code Playgroud) 我有以下代码示例在delphi xe5 update 2中编译.
procedure TForm1.FormCreate(Sender: TObject);
var i,t:Integer;
buf: array [0..20] of TPair<Integer,Integer>;
begin
t := 0;
for i := Low(buf) to High(buf) do begin
ShowMessage(
Format(
'Pointer to i = %p;'#$d#$a+
'Pointer to buf[%d].Key = %p;'#$d#$a+
'Pointer to buf[%d].Value = %p;'#$d#$a+
'Pointer to t = %p',
[@i, i, @(buf[i].Key), i, @(buf[i].Value), @t]
)
);
buf[i].Key := 0;
buf[i].Value := 0;
t := t + 1;
end;
end;
Run Code Online (Sandbox Code Playgroud)
如果我运行它它会向我显示变量的地址.变量i并t在内存范围内有地址buf!
当i达到3时,赋值buf[i].Value …
我想从MS Access文件中读取整个表,我正在尝试尽快完成.在测试大样本时,我发现循环计数器在读取与表的最后记录相比的最高记录时增加得更快.这是一个演示此示例的示例代码:
procedure TForm1.Button1Click(Sender: TObject);
const
MaxRecords = 40000;
Step = 5000;
var
I, J: Integer;
Table: TADOTable;
T: Cardinal;
Ts: TCardinalDynArray;
begin
Table := TADOTable.Create(nil);
Table.ConnectionString :=
'Provider=Microsoft.ACE.OLEDB.12.0;'+
'Data Source=BigMDB.accdb;'+
'Mode=Read|Share Deny Read|Share Deny Write;'+
'Persist Security Info=False';
Table.TableName := 'Table1';
Table.Open;
J := 0;
SetLength(Ts, MaxRecords div Step);
T := GetTickCount;
for I := 1 to MaxRecords do
begin
Table.Next;
if ((I mod Step) = 0) then
begin
T := GetTickCount - T;
Ts[J] := T;
Inc(J);
T …Run Code Online (Sandbox Code Playgroud)