我不希望用户摆弄Share对话框.还欢迎更改共享名称,评论,用户限制等其他信息.
谢谢SoulBlade(使用Delphi 7)
如何指定在Delphi中调用哪个基类的重写方法?
比方说,像这样的继承行:TObject - > ... SomeMoreBaseClass ... - > ParentClass - > MyClass
假设ParentClass没有Create(),但它有一个Create(int = 0).这样当你调用ParentClass.Create()时,它实际上调用ParentClass.Create(0)
现在,在MyClass的构造函数Create()中,如果我调用"inherited;",我发现我没有得到ParentClass.Create(0),而是得到基类的.Create()甚至是TObject.
那么,我怎样才能调用ParentClass.Create()?
最简单的是"继承Create(0)",但它感觉不够"正确".
(在我的情况下,ParentClass实际上是System.Generics.Collections.TDictionary)
type
TParentClass = class
public
constructor Create(n:Integer = 0);
end;
TDerivedClass = class(TParentClass)
public
constructor Create; // Note: no parameters
end;
constructor TDerivedClass.Create;
begin
// inherited; // this calls TObject.Create, not TParentClass.Create(0);
inherited Create(0);
end;
Run Code Online (Sandbox Code Playgroud) 我希望使用Sender作为TObject作为我的case ...语句的选择标准
procedure TForm.ShowGUI (Sender: TObject);
begin
case sender of
ToolButton1: begin
do_something;
end;
ToolButton2: begin
///
end;
ToolButton3: begin
do_stufff_here;
end;
ToolButton3: begin
///
end;
else ;
end;
end;
Run Code Online (Sandbox Code Playgroud)
根据case语句的要求使发件人成为序数类型的技巧?
我需要一个正则表达式,匹配从指定位置到第一个字符的字符串反向.字符串是一些文件名.
您可以按照以下步骤从"New Document.extension"到"New docu":
对于"This Is My Longest Document.ext1.ext2"示例:
最近我发现自己依赖于自定义[属性]分配.我正在寻求创建我经常使用的VCL控件的RTTI和Generics变体; 我的目的是将样板代码的数量减少到最少,我发现RTTI,匿名方法和属性非常棒.
我有一个不寻常的问题.由于我最终使用了很多[Attributes],我需要一种可读的方式来格式化这段代码.可能听起来像一个微不足道的问题,但我对我的格式和缩进非常着迷.属性的问题在于IDE没有以特殊方式格式化它们.在具有[Attribute]声明的多个字段声明的块中,您很难猜测什么是类型,什么是属性,什么属性适用于哪个字段.这是一个最小的例子:
type
[OneAttribute('SomeParam', 7), AnOtherAttribute]
TSomething = class
public
[OneAttribute('SomeParam', 7), AnOtherAttribute]
FieldName: string;
[OneAttribute('SomeParam', 7), AnOtherAttribute]
OtherField: Integer;
[OneAttribute('SomeParam', 7), AnOtherAttribute]
function Sum(a,b:Integer):Currency;
[OneAttribute('SomeParam', 7), AnOtherAttribute]
property Name:string read FieldName write FieldName;
end;
Run Code Online (Sandbox Code Playgroud)
我在上面的例子中形成那些[Attributes]的方式是在C#代码中最常见的方式; 不幸的是我没有看到使用属性的Delphi代码的例子,除了我自己的.这样做效果稍好,C#因为您不太可能将属性应用于实际字段,更有可能将它们应用于properties或functions; 因为在C#函数实现中紧跟它的声明(对于属性来说是相同的),所以你得不到与Delphi相同的块; 函数和属性声明自然是分开的,因此对代码的浏览不会受到属性使用的阻碍.
我尝试了与delphi相关的"样式"信息的明显来源.Delphi 2010中的代码格式化程序根本不理解属性声明!在上面的示例中,如果我删除public关键字并运行内置代码格式化程序,那么第一行的Attributes声明会在class关键字后面移动一行,就像它声明一个祖先类一样.
我围绕着Delphi 2010源代码.要么我的grep-fu严重失败,要么在整个Delphi 2010源代码中绝对没有使用属性.需要明确的是,在尝试grep实际使用属性之后(很难因为使用了方括号而且它们很少意味着它是属性声明)我开始贪图TCustomAttribute:没有TCustomAttribute任何地方的后代,所以很明显没有使用属性.
最后的问题:
我的最新解决方案如下:
type
[OneAttribute('SomeParam', 7), AnOtherAttribute]
TSomething = class
public …Run Code Online (Sandbox Code Playgroud) Delphi Xe,Win7x64
如何从进程名称(exe文件的完整路径)获取主窗口句柄,或至少一个类或窗口名称(如果该进程只有一个窗口).
例:
function MyGetWinHandle(path:String):HWND;
...
handle := MyGetWinHandle('c:\windows\system32\notepad.exe');
Run Code Online (Sandbox Code Playgroud) 我正在开发一个简单的多线程网络爬虫.我使用sqlite数据库来存储将被扫描的URL.我只有一个数据库句柄,问题是主线程查询数据库以生成新线程.线程访问相同的句柄但主线程也.
我已经为每个线程定义了关键部分,包括主线程.但是如果一个线程也处于一个关键部分,那么主线程会继续执行代码eaven.
这是一些代码:
CreateDb;
InitializeCriticalSection(critical);
index := 0;
repeat
if threads < THREADS_MAX then
begin
EnterCriticalSection(critical);
try
sqldb.query('SELECT * FROM urls WHERE vizitat=0 AND id>' + IntToStr(index));
urlcount:= sqldb.rowcount;
for i:= 1 to urlcount do
begin
WriteLn(sqldb.Fs('adresa'));
sqldb.next;
index := sqldb.Fi('id');
with TPageCrawl.Create(@threads,sqldb.Fs('adresa'),index,sqldb) do;
if threads = THREADS_MAX then break;
end;
LeaveCriticalSection(critical);
except
LeaveCriticalSection(critical);
Continue;
end;
end;
Write(logo);
Sleep(1000);
until (threads = 0) and (urlcount < 1);
Run Code Online (Sandbox Code Playgroud) 我有两个地区说rgn1和rgn2.我想使用CombineRgn函数将它们组合在一起.所以我写 -
if CombineRgn(rgnMain,rgn1,rgn2,RGN_OR) = error then
ShowMessage('error');
Run Code Online (Sandbox Code Playgroud)
它的返回值为ERROR.
我测试过rgn1和rgn2是正确的区域.
谢谢.
这是在两台运行Windows XP Pro SP3的机器上进行的,但它在Delphi IDE内外的开发机器上运行正常.
运行Windows XP专业版.在Delphi 2010下编译的exe.
当我运行exe时,我收到Windows报告错误"Neopos.exe遇到了问题,需要关闭.我们很抱歉给您带来不便"
我知道它正在以主窗体的形式创建.
Application.Initialize; //Runs this
Application.CreateForm(TfmMain, fmMain); //FAILS HERE
Run Code Online (Sandbox Code Playgroud)
它没有达到:TfmMain.FormCreate(Sender: TObject);主窗体中的过程,我不知道如何跟踪此错误并进行调试.
之间发生了什么:Application.CreateForm(TfmUDF, fmUDF);和procedure TfmMain.FormCreate(Sender: TObject)我的主要形式.
我如何跟踪这个以找出导致Windows错误的原因.
当然,Windows错误报告包含很长的信息列表.我在哪里可以查找原因或至少找出错误原因的线索.
这个错误现在已经停止了所有开发工作(并破坏了我的周末)所以我迫切需要解决这个问题.
任何人都可以解释一下为什么我在下面的块读取中遇到'I/O错误998'?
function ReadBiggerFile: string;
var
biggerfile: file of char;
BufArray: array [1 .. 4096] of char; // we will read 4 KB at a time
nrcit, i: integer;
sir, path: string;
begin
path := ExtractFilePath(application.exename);
assignfile(biggerfile, path + 'asd.txt');
reset(biggerfile);
repeat
blockread(biggerfile, BufArray, SizeOf(BufArray), nrcit);
for i := 1 to nrcit do
begin
sir := sir + BufArray[i];
Form4.Memo1.Lines.Add(sir);
end;
until (nrcit = 0);
closefile(biggerfile);
ReadBiggerFile := sir;
end;
Run Code Online (Sandbox Code Playgroud) delphi ×10
winapi ×2
attributes ×1
coding-style ×1
constructor ×1
delphi-7 ×1
inheritance ×1
regex ×1
region ×1
share ×1
unc ×1