小编Som*_*One的帖子

如何在Delphi中将异常从一个线程传递到另一个(调用者的)线程?

我有另一个问题!请看这个例子:

// There is a class with some method:
type
  TMyClass = class
  public
    procedure Proc1;
  end;

  // There is a some thread class:
  TMyThread = class(TThread)
  protected
    procedure Execute; override;
  end;

procedure TMyClass.Proc1;
begin
  // this method is just calling another thread:
  with TMyThread.Create(True) do
  begin
    FreeOnTerminate := True;
    Resume;
  end;
  // + there are some more actions
end;

procedure TMyThread.Execute;
begin
  // in this example this thread just throws exception:
  raise Exception.Create('Some exception');
end;
Run Code Online (Sandbox Code Playgroud)

所有我想要的 - 是在TMyClass.Proc1中引发异常并将其抛出如下:

var …
Run Code Online (Sandbox Code Playgroud)

delphi multithreading

10
推荐指数
2
解决办法
2093
查看次数

从TextFile中删除前N个字符而不创建新文件(Delphi)

我只是想从指定的文本文件中删除前N个字符,但我卡住了.请帮帮我!

procedure HeadCrop(const AFileName: string; const AHowMuch: Integer);
var
  F: TextFile;
begin
  AssignFile(F, AFileName);
  // what me to do next?
  // ...
  // if AHowMuch = 3 and file contains"Hello!" after all statements
  // it must contain "lo!"
  // ...
  CloseFile(F);
end;
Run Code Online (Sandbox Code Playgroud)

我试图使用TStringList,但它还附加了行尾字符!

with TStringList.Create do
try
  LoadFormFile(AFileName); // before - "Hello!"
  // even there are no changes...
  SaveToFile(AFileName); // after - "Hello!#13#10"
finally
  Free;
end;
Run Code Online (Sandbox Code Playgroud)

谢谢!

delphi pascal text-files

6
推荐指数
1
解决办法
1358
查看次数

在Delphi中使用自定义值进行枚举

可以在Delphi 5中用自定义值声明枚举吗?

type
  MyEnum = (meVal1 = 1, meVal2 = 3); // compiler error
Run Code Online (Sandbox Code Playgroud)

谢谢!

delphi enums delphi-5

5
推荐指数
2
解决办法
2290
查看次数

如何在Oracle 11g r2中简单地更改XMLTYPE的节点属性值?

我只想更改这个XML(包含在XMLTYPE变量中)名为"ChildNode"的所有节点,其中"Name"="B"属性值为"C":

<RootNode>
  <ChildNodes>
    <ChildNode Name="A"/>
    <ChildNode Name="B"/>
  </ChildNodes>
</RootNode>

DECLARE
  FXML XMLTYPE;
BEGIN
  FXML := ...; -- see text before
  -- what next?
END;
Run Code Online (Sandbox Code Playgroud)

谢谢!

oracle plsql

4
推荐指数
1
解决办法
2万
查看次数

如何从Delphi中的子类获取指向基类中方法的指针?

这是我的代码示例:

type
  TMyBaseClass = class
  public
    procedure SomeProc; virtual;
  end;

  TMyChildClass = class(TMyBaseClass)
  public
    procedure SomeProc; override;
  end;

var
  SomeDelegate: procedure of object;

procedure TMyBaseClass.SomeProc;
begin
  ShowMessage('Base proc');
end;

procedure TMyChildClass.SomeProc;
begin
  ShowMessage('Child proc');
  // here i want to get a pointer to TMyBaseClass.SomeProc (NOT IN THIS CLASS!):
  SomeDelegate := SomeProc;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TMyChildClass.Create do
  try
    // there will be "Child proc" message:
    SomeProc;
  finally
    Free;
  end;
  // there i want to get "Base proc" message, …
Run Code Online (Sandbox Code Playgroud)

delphi

3
推荐指数
1
解决办法
1067
查看次数

标签 统计

delphi ×4

delphi-5 ×1

enums ×1

multithreading ×1

oracle ×1

pascal ×1

plsql ×1

text-files ×1