Delphi 2010引入了可以添加到类型声明和方法的自定义属性.哪个语言元素可以使用自定义属性?
到目前为止我找到的例子包括类声明,字段和方法.(而AFAIK泛型类不支持自定义属性).
本文中显示了一些示例.看起来变量(任何类声明的外部)也可以具有属性.
根据这篇文章,可以使用属性
是否有其他语言元素可以放置属性?
更新:本文指出自定义属性可以放在属性之前:http://francois-piette.blogspot.de/2013/01/using-custom-attribute-for-data.html
它包含以下代码示例:
type
TConfig = class(TComponent)
public
[PersistAs('Config', 'Version', '1.0')]
Version : String;
[PersistAs('Config', 'Description', 'No description')]
Description : String;
FTest : Integer;
// No attribute => not persistent
Count : Integer;
[PersistAs('Config', 'Test', '0')]
property Test : Integer read FTest write FTest;
end;
Run Code Online (Sandbox Code Playgroud)
我想还有一种方法可以读取方法参数的属性,比如
procedure Request([FormParam] AUsername: string; [FormParam] APassword: string);
Run Code Online (Sandbox Code Playgroud) Delphi 2010有一套很好的新文件访问功能IOUtils.pas(我特别喜欢与日期相关的函数的UTC版本).到目前为止我想念的是类似的东西
TFile.GetSize (const Path : String)
Run Code Online (Sandbox Code Playgroud)
什么是Delphi 2010-获取文件大小的方法?我是否必须返回并使用FindFirst访问TSearchRec.FindData?
谢谢.
我正在寻找一个免费的,最新的Delphi 2010加密库,它实现了RSA和AES(Rijndael).
我想要一个免费的库,因为我打算编写并发布一些将使用它的示例代码.
Delphi 2010版本的TurboPower LockBox已经发布到SongBeamer网站,它实现了这两个,但我担心它会变得有点旧.例如,小RSA密钥大小并且多年没有新的安全功能.
更新: 是否认为LockBox已过期或缺少重要功能?它仍然与生产发展有关吗?(特别是RSA密钥大小)
我有一个TWICImage,IWicBitmap和一个IWicBitmapSource,可以很好地显示所有支持的图形文件格式,允许旋转,水平翻转,垂直翻转,缩放和剪切.所有这些似乎都运行良好,我可以得到WicImages像素格式,但我无法弄清楚如何更改或设置TWICImage的pixelformat.
我创建了一个对话框来返回WICPixelFormatGUID以用作转换的pixelformat.
任何人都可以共享一些代码,演示如何使用IWICColorTransform或其他Wincodec方法更改WicImage的pixelformat?
法案
它现在到2011年中期......所以对于那些可能想知道的人我试过这个并且它似乎有用(它使用Developer Express的TcxImage,但我怀疑TImage也能正常工作):
procedure TForm1.N16bitBGR1Click( Sender: TObject );
var
wicImg: TWICImage;
wicBitmap: IWICBitmap;
iBmpSource: IWICBitmapSource;
puiWidth, puiHeight: UINT;
iConverter: IWICFormatConverter;
begin
if cxImage1.Picture.Graphic is TWICImage then
begin
Screen.Cursor := crHourGlass;
try
wicImg := TWICImage( cxImage1.Picture.Graphic );
wicImg.ImagingFactory.CreateFormatConverter( iConverter );
iBmpSource := wicImg.Handle as IWICBitmapSource;
iBmpSource.GetSize( puiWidth, puiHeight );
iConverter.Initialize( iBmpSource, GUID_WICPixelFormat16bppBGR555, WICBitmapDitherTypeNone, nil, 0,
WICBitmapPaletteTypeMedianCut );
wicImg.ImagingFactory.CreateBitmapFromSourceRect( iConverter, 0, 0, puiWidth, puiHeight, wicBitmap );
if Assigned( wicBitmap ) then
wicImg.Handle := wicBitmap;
cxImage1.Repaint;
cxImage1.Update;
cxImage1.Invalidate;
dxStatusBar1.Panels[ 0 …Run Code Online (Sandbox Code Playgroud) 有没有人知道一个实用程序,可以自动检测和删除uses条款中的不需要的单位?
最好..
提前致谢.
我按顺序继承了一个控件,所以我可以添加一些我需要的字段,但现在当我在运行时创建它时,我得到一个Access Violation.不幸的是,这种访问冲突不会发生在我正在创建控件的地方,甚至那些我在启用所有调试选项的情况下构建的(包括"使用调试DCU构建")堆栈跟踪根本无法帮助我!
在我尝试重现错误时,我尝试创建一个控制台应用程序,但显然这个错误只出现在Forms应用程序中,并且只有当我的控件实际显示在表单上时!
以下是重现错误的步骤.创建一个新的VCL Forms应用程序,单击一个按钮,双击以创建OnClick处理程序并写入:
type TWinControl<T,K,W> = class(TWinControl);
procedure TForm3.Button1Click(Sender: TObject);
begin
with TWinControl<TWinControl, TWinControl, TWinControl>.Create(Self) do
begin
Parent := Self;
end;
end;
Run Code Online (Sandbox Code Playgroud)
每次我尝试时,这都会连续生成访问冲突.仅在Delphi 2010上测试过,因为这是我在这台计算机上唯一的版本.
问题是:
以下是质量控制报告的链接:http://qc.embarcadero.com/wc/qcmain.aspx?d = 112101
在寻找替代GDI的替代方案时,我试图在Windows 7中测试Delphi的2010 TDirect2DCanvas性能.
我通过使用Direct2D绘制一条巨大的折线来测试它,结果非常慢,即使数据量少于我使用GDI进行相同测试的数量少500倍(我甚至没有在GDI中使用位图作为后备缓冲,我只是直接绘制到表单画布).
所以我想:
a) Direct2D比GDI慢;
b) TDirect2DCanvas很慢;
c)我做错了什么
,希望它是c).
我写的测试代码是:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Direct2D, D2D1;
type
TForm2 = class(TForm)
private
{ Private declarations }
FD2DCanvas: TDirect2DCanvas;
FData: array[0..50000] of TPoint;
public
procedure CreateWnd; override;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses utils;
{$R *.dfm}
procedure TForm2.CreateWnd;
var
i: Integer; …Run Code Online (Sandbox Code Playgroud) 这是由如何比较TFunc/TProc包含对象的功能/过程?,特别是大卫对巴里问题的评论.由于我没有博客发布这个问题,我将在这里提出这个问题并回答.
问题:Delphi的匿名方法中何时以及如何引用变量?
例:
procedure ProcedureThatUsesAnonymousMethods;
var V: string;
F1: TFunc<string>;
F2: TFunc<string>;
begin
F1 := function: string
begin
Result := V; // references local variable
end
V := '1';
F2 := function: string
begin
Result := V;
end
V := '2';
ShowMessage(F1);
ShowMessage(F2);
end;
Run Code Online (Sandbox Code Playgroud)
两者ShowMessage都将展示2.为什么?如何V捕获以及何时捕获?
我在我的应用程序中嵌入PHP(在Delphi 2010中编写),使用PHP4Delphi组件与php5ts.dll连接.我想我的程序充当PHP(sapi模块?)的扩展,因为它注册了一些可以在PHP脚本中使用的函数和常量......无论如何,在使用简单数据类型时效果很好,但是当我尝试使用多维数组时作为返回值我得到错误
Access violation at address 01CD3C35 in module 'php5ts.dll'. Read of address 0231E608.
堆栈列表
(000A2C35){php5ts.dll} [01CD3C35] destroy_op_array + $35
(004C4D61){myApp.exe } [008C5D61] php4delphi.TPHPEngine.ShutdownEngine (Line 1497, "php4delphi.pas" + 17) + $7
php4delphi.pas中的第1497行是调用的 tsrm_shutdown();
对我来说,它看起来像垃圾收集器在脚本结束时崩溃,所以我怀疑我没有正确地将数据发送回引擎...因此我的问题是如何将多维数组发送回PHP?
我正在使用的模式是
var subArray: pzval;
_array_init(return_value, nil, 0);
for x := 0 to Data.Count-1 do begin
subArray := MAKE_STD_ZVAL;
_array_init(subArray, nil, 0);
// populate subarray with data, including other subarrays
...
// add subarray to the main array
add_index_zval(return_value, x, subArray);
end;
Run Code Online (Sandbox Code Playgroud)
我是否必须"注册"我创建的子阵列?我必须增加或减少refcount或设置is_ref?IOW,如何设置子数组的return_value和zvals? …
如何计算Delphi中字符串中某个字符的出现次数?
例如,假设我有以下字符串并且想要计算其中的逗号数:
S := '1,2,3';
Run Code Online (Sandbox Code Playgroud)
然后我想获得2结果.
delphi ×10
delphi-2010 ×10
delphi-xe ×2
delphi-xe2 ×2
annotations ×1
direct2d ×1
encryption ×1
file ×1
gdi ×1
php4delphi ×1