两个Cardinal和Single是4字节/ 32比特的数据类型,但是当我他们类型强制转换为彼此我得到一个Invalid Typecast错误的Delphi 10.1(柏林).
lSingleVar := Single(lCardinalVar);
Run Code Online (Sandbox Code Playgroud)
我不是在谈论在两种类型之间进行转换,因为它只存储23位基数数据(Single数据类型的小数部分).我需要将至少30位数据存储到Single变量中.我有充分的理由(类型无法更改),我将很乐意详述.
我如何对Single变量进行类型转换?
在主窗体上添加一个Tbutton和一个TSaveDialog
在SaveDialog1的属性中将"ofOverwritePrompt"设置为True
使用:
procedure TForm1.Button1Click(Sender: TObject);
begin
SaveDialog1.Execute();
end;
Run Code Online (Sandbox Code Playgroud)运行应用程序.按按钮执行保存对话框.尝试保存到已存在的文件.如果要替换文件,则会出现一个消息框.按取消.到目前为止都很好.关闭应用程序.
转到项目/选项/应用程序/外观并选择自定义样式(例如Amakrits).将Amakrits设置为默认样式.
(使用TFileSaveDialog会得到相同的结果)
如果我使用Delphi XE8编译并运行应用程序就可以了,因为即使选择了另一种样式,保存对话框窗口似乎也使用默认的窗口样式.
编辑:我有Windows 10专业版.使用Delphi 10.1 Berlin编译为win32的源代码.替换消息框部分隐藏.仅显示左上方的小部分,请参见图.
这里用XE8 win32编译:
PS.我使用默认的100%比例因子.
使用win64(Delphi 10.1 Berlin)编译似乎没问题:
因此,编译为win32对我来说不起作用,但64位会.有线索吗?
编辑:尝试使用"GetSaveFileName(OFN)"也不适合我在win32(胜利64是好的):
我如何在TVirtualInterface类的OnInvoke方法中获得Method:TRttiMethod的所有权属性?
我有这个界面:
IPerson = interface(IInvokable)
['{45CE428C-F880-4D61-A2C1-0F3CB47130B5}']
procedure SetName(const Value: string);
function GetName(): string;
[TEntityField('Field Name Here')]
property Name: string read GetName write SetName;
end;
Run Code Online (Sandbox Code Playgroud)
而这堂课:
type
TVirtualEntity<T: IInvokable> = class(TVirtualInterface)
public
constructor Create(); reintroduce; overload;
end;
constructor TVirtualEntity<T>.Create;
begin
inherited Create(TypeInfo(T));
Self.OnInvoke :=
procedure(Method: TRttiMethod; const Args: TArray<TValue>; out Result: TValue)
var
attributes: TArray<TCustomAttribute>;
attributesManager: TAttributesManager;
entityFieldAttribute: TEntityField;
begin
attributesManager := TAttributesManager.Create(Method.GetAttributes);
try
if attributesManager.HasAttribute<TEntityField>() then
begin
Result := attributesManager.GetAttribute<TEntityField>.FieldName;
end;
finally
attributesManager.Free;
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
我想获得方法的TRttiProperty:TRttiMethod,但是怎么样?如果我将界面更改为:
IPerson = interface(IInvokable) …Run Code Online (Sandbox Code Playgroud) HTML字符实体𝕒:
可以使用此HTML代码从数字120146创建:
<!DOCTYPE html>
<html>
<style>
body {
font-size: 20px;
}
</style>
<body>
<p>I will display 𝕒</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
其中一些扩展字符符号可以在HTML和Delphi 10.1.2中使用相同的数字值创建.例如:
双方®并Chr(174)创建了"注册商标"符号字符®
双方£并Chr(163)创建了"咚咚"标记符号£
等等.
不幸的是,这不符合上述数量的情况下120146,其中Chr(120146)在Delphi中创建一个"有趣的中国符号".
那么如何𝕒从Delphi中的数字120146创建上面的字符符号?哪个是数值范围,HTML和Delphi之间的上述数字等价是否有效?
调试我的代码,我注意到Delphi编译器(柏林10.1)没有警告没有返回值的函数.这是正常的吗?
一个简单的例子:
function f(s:string):String;
begin
stringreplace(s,#32,'',[rfReplaceAll]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
showmessage(F('te st'));
end;
Run Code Online (Sandbox Code Playgroud)
这条线
stringreplace(s,#32,'',[rfReplaceAll]);
Run Code Online (Sandbox Code Playgroud)
应该
result:= stringreplace(s,#32,'',[rfReplaceAll]);
Run Code Online (Sandbox Code Playgroud)
没有警告!
我认为它应该警告"返回值可能未定义".但事实并非如此.我在最后几天更改并重写了旧代码的一部分.我恐怕在我的申请中有这种错误.
很容易检测到a的垂直滚动条TScrollBox是否位于最顶层:
IsScrollBarAtTop := ScrollBox1.VertScrollBar.Position = 0;
Run Code Online (Sandbox Code Playgroud)
但是如何检测a的垂直滚动条TScrollBox是否处于非常底部?
我TRegEx在Delphi 10.1.2中看到了几个Delphi的使用示例,如下所示:
try
RegexObj := TRegEx.Create(REGEX_EXTRACTEMAILADDRESSES, [roIgnoreCase]);
MatchResults := RegexObj.Match(ThisPageText);
while MatchResults.Success do
begin
slEmailAddressesOnThisPage.Add(MatchResults.Value);
MatchResults := MatchResults.NextMatch();
end;
except
on E: ERegularExpressionError do
begin
// Todo: Log Syntax error in the regular expression
end;
end;
Run Code Online (Sandbox Code Playgroud)
所以我想知道TRegEx在这样的例子中创建后是否必须显式释放对象?
有没有办法从父类调用子类的创建?下面是这个Duplicate方法,我希望调用子类的构造函数,以便底部的测试成功.
type
IBla<T> = interface(IInvokable)
['{34E812BF-D021-422A-A051-A492F25534C4}']
function GetIntFromIface(): Integer;
function Duplicate(): IBla<T>;
end;
TClassA<T> = class(TInterfacedObject, IBla<T>)
protected
function GetInt(): Integer; virtual;
public
function GetIntFromIface(): Integer;
function Duplicate(): IBla<T>;
end;
TClassB = class(TClassA<Integer>, IBla<Integer>)
protected
function GetInt(): Integer; override;
end;
function TClassA<T>.Duplicate: IBla<T>;
begin
Exit(TClassA<T>.Create());
end;
function TClassA<T>.GetInt: Integer;
begin
Exit(1);
end;
function TClassA<T>.GetIntFromIface: Integer;
begin
Exit(GetInt());
end;
function TClassB.GetInt: Integer;
begin
Exit(2);
end;
procedure TestRandomStuff.Test123;
var
o1, o2: IBla<Integer>;
begin
o1 := TClassB.Create();
o2 := o1.Duplicate();
Assert.AreEqual(o2.GetIntFromIface, 2);
end;
Run Code Online (Sandbox Code Playgroud) 有以下泛型课程
TTuple<T1, T2> = class
protected
fItem1: T1;
fItem2: T2;
public
constructor Create; overload;
constructor Create(Item1: T1; Item2: T2); overload;
destructor Destroy; override;
property Item1: T1 read fItem1 write fItem1;
property Item2: T2 read fItem2 write fItem2;
end;
constructor TTuple<T1, T2>.Create;
begin
inherited;
end;
constructor TTuple<T1, T2>.Create(Item1: T1; Item2: T2);
begin
fItem1 := Item1;
fItem2 := Item2;
end;
destructor TTuple<T1, T2>.Destroy;
begin
inherited;
end;
Run Code Online (Sandbox Code Playgroud)
并以如下方式使用:
x := TTuple<TObjectList<TMyObjects>, Integer>.Create;
Run Code Online (Sandbox Code Playgroud)
我需要手动释放fitem1.如何释放析构函数中的fItem1?
delphi ×10
button ×1
generics ×1
html ×1
regex ×1
rtti ×1
scrollbar ×1
tscrollbox ×1
vcl-styles ×1