在Delphi XE2中,如果我在项目管理器中选择一个文件,则Object Inspector会显示该文件的属性.什么是"设计类"属性以及如何使用它?
我想将标准窗口信息(和警告和错误)图标绘制到pagecontrol的选项卡的索引.但是,如果窗口背景颜色不是白色,则结果看起来很糟糕.
program Project111;
uses
Vcl.Forms,
Vcl.Controls,
Vcl.Graphics,
Winapi.Windows,
Vcl.ComCtrls,
Vcl.ImgList;
{$R *.res}
var
mainForm: TForm;
imageList: TImageList;
icon: TIcon;
pageControl: TPageControl;
tabSheet: TTabSheet;
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm, mainForm);
imageList := TImageList.Create(mainForm);
imageList.ColorDepth := cd32bit;
icon := TIcon.Create;
try
icon.Handle := LoadImage( 0, IDI_INFORMATION, IMAGE_ICON, 16, 16, {LR_DEFAULTSIZE or} LR_SHARED );
imageList.AddIcon(icon);
finally
icon.Free;
end;
pageControl := TPageControl.Create(mainForm);
pageControl.Parent := mainForm;
pageControl.Images := imageList;
tabSheet := TTabSheet.Create(mainForm);
tabSheet.Parent := pageControl;
tabSheet.PageControl := pageControl;
tabSheet.ImageIndex := 0;
Application.Run;
end.
Run Code Online (Sandbox Code Playgroud)
这是一个截图: …
我想设置表达式树中引用的属性值。
using System;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;
namespace ConsoleApp8
{
class TestObject
{
public double X { get; set; }
}
class Program
{
static Action<double> GetSetterForX(Expression<Func<double>> expression)
{
var body = expression.Body;
var operand = body as MemberExpression;
var propertyInfo = (PropertyInfo) (operand.Member);
var setter = propertyInfo.GetSetMethod(true);
// At this point I have the setter. But how do I get access to the testObject?
return null;
}
static void Main(string[] args)
{
var testObject = new TestObject(); …Run Code Online (Sandbox Code Playgroud) 我试图在TEnumerator中公开构建私有静态数组.
Delphi本身允许直接枚举静态数组(见下文),所以我怀疑Delphi在后台为静态数组创建一个枚举器,我希望我能够在GetEnumerator方法中创建和公开相同的枚举器.
(我使用的是Delphi XE2).
program Project6;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Generics.Collections;
type
TMyEnum = (meA, meB);
TMyClass = class
private
FItems: array[TMyEnum] of Integer;
protected
public
function GetEnumerator: TEnumerator<Integer>;
end;
{ TMyClass }
function TMyClass.GetEnumerator: TEnumerator<Integer>;
begin
// What is the simplies way of creating this enumerator?
end;
var
myObj: TMyClass;
i: Integer;
begin
myObj := TMyClass.Create;
try
// This works but only in the same unit
for i in myObj.FItems do
WriteLn(i);
for i in myObj do …Run Code Online (Sandbox Code Playgroud) delphi ×3
delphi-xe2 ×2
.net ×1
arrays ×1
c# ×1
enumerator ×1
icons ×1
static-array ×1
tpagecontrol ×1