标签: delphi-10.1-berlin

在德尔福柏林中,UTF-8字符串显示为反斜杠,后跟数字"\ 0646"?

有些人能帮助我正确显示UTF-8 unicode字符串吗?

我正在调用一个从Web服务接收文本字符串的过程.该过程工作正常,字符串被完美地接收.但是,由于字符串包含UTF-8文本,因此它将unicode字母显示为数字...

{"displayName":"\u062a\u0637\u0628\u064a\u0640\u0640\u0640\u0642 \u062f\u0639\u0640\u0640\u0640\u0640\u0640\u0627\u0621"
Run Code Online (Sandbox Code Playgroud)

德尔福柏林应该支持UTF-8,但我没有使用哪个函数来编码UTF-8并显示文本(阿拉伯语文本)!!

Procedure TF_Main.GnipHTTPSTransfer(Sender: TObject; Direction: Integer; BytesTransferred: Int64; PercentDone: Integer; Text: String);
Begin
  Inc(Transfer_Count);
  L_Counter.Caption:=IntToStr(Transfer_Count);
  write(GNIP_Text_File, Text);
  M_Memo.Lines.Add(text);
End;
Run Code Online (Sandbox Code Playgroud)

delphi unicode delphi-10.1-berlin

0
推荐指数
1
解决办法
562
查看次数

如何将毫秒日期转换为DateTime?

我这次来自服务器:1475245457452这个日期和时间是:30.9.2016,16:24:17

我怎么能把Delphi中的这个1475245457452转换成一个正确的日期和时间?

delphi delphi-10.1-berlin

0
推荐指数
1
解决办法
802
查看次数

最简单的方式来显示不同风格的按钮

我想基于设计模板对旧的VCL应用程序进行现代化.该设计模板包含不同的按钮样式.比方说,有三种类型的按钮:LightButton,DarkButtonGreenButton.

由于DarkButtonTButton使用位图样式设计器修改了暗设计的外观,因此超过50%的按钮都会出现.

现在我想将其他按钮样式添加到.vsf文件中并在我的应用程序中使用它.最好的方法是什么?

我是否需要创建新的按钮类和新的后代,TStyleHook其中绘制全新的按钮?如果是,是否有办法尽可能多地重用代码Vcl.StdCtrls.TButtonStyleHook

还有其他方法,最佳实践或示例吗?

delphi vcl vcl-styles delphi-10.1-berlin

0
推荐指数
1
解决办法
305
查看次数

无法使用 TIdSMTP 发送 UTF-8 消息

我有按钮发送邮件:

procedure TRealization.Button17Click(Sender: TObject);
var
  EmailCore: TStringStream;
  EmailBody, sInvoices: string;
  FilePath: string;
  MailTitle: string;
  i: integer;
begin
  if (Languages.ItemIndex > -1) then begin
    EmailCore := TStringStream.Create('', TEncoding.UTF8);
    if Languages.ItemIndex = 0 then begin
        FilePath := ExtractFilePath(Application.ExeName)+'/languages/pl.html';
        MailTitle := 'P?atno?? dla '+Monitoring.l_client_name.Caption;
    end else if Languages.ItemIndex = 1 then begin
        FilePath := ExtractFilePath(Application.ExeName)+'/languages/en.html';
        MailTitle := 'Invoice payment for '+Monitoring.l_client_name.Caption;
    end;
    EmailCore.LoadFromFile(FilePath);
    for i := 0 to (preview_invoices.RowCount-1) do begin
      sInvoices := sInvoices+'<tr><td>'+preview_invoices.Cells[2,i]+'</td><td>'+preview_invoices.Cells[4,i]+'</td><td>'+preview_invoices.Cells[4,i]+'</td><td>'+preview_invoices.Cells[5,i]+'</td><td>'+preview_invoices.Cells[6,i]+'</td></tr>';
    end;
    EmailBody := StringReplace(EmailCore.DataString, ':LIST:', sInvoices, [rfReplaceAll]);
    EmailBody := …
Run Code Online (Sandbox Code Playgroud)

delphi indy utf-8 indy10 delphi-10.1-berlin

0
推荐指数
1
解决办法
1145
查看次数

FormClose继承

我对Delphi很新(我使用的是版本10.1柏林),我试图理解继承是如何工作的.

假设我有2个表单,在关闭时必须执行相同的操作.为了避免代码重复,我最初的想法是创建一个TFoobarForm继承自的超类,TForm然后创建一个FormClose这样的过程:

procedure TFoobarForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  { Some code }
end;
Run Code Online (Sandbox Code Playgroud)

在那之后,我想创建两个表单,让我们说,TFooFormTBarForm继承自TFoobarForm.但我不知道是否有办法使这些新表单执行超类FormClose操作,而无需从继承自它的每个类手动调用该过程.

最后,我正在寻找的是一种避免写这个的方法:

procedure TFooForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited FormClose(Sender, Action);
end;
Run Code Online (Sandbox Code Playgroud)

对于每个子类TFoobarForm.

delphi inheritance delphi-10.1-berlin

0
推荐指数
1
解决办法
171
查看次数

使用 TStringList 的奇怪 EOutOfMemory 异常

我有一个系统,它加载一些压缩到“.log”文件中的文本文件,然后使用多个线程将其解析为信息类,每个线程处理不同的文件并将解析的对象添加到列表中。该文件是使用 TStringList 加载的,因为它是我测试过的最快的方法。

文本文件的数量是可变的,但通常我必须在一次入侵中处理 5 到 8 个文件,范围从 50Mb 到 120Mb。

我的问题:用户可以根据需要多次加载 .log 文件,在其中一些进程之后,我在尝试使用 TStringList.LoadFromFile 时收到 EOutOfMemory 异常。当然,任何使用过 StringList 的人首先想到的是在处理大文本文件时不应该使用它,但是这个异常是随机发生的,并且在该过程至少成功完成一次之后(对象在新解析开始之前被销毁,因此除了一些小泄漏之外,内存可以正确检索)

我尝试使用textile 和TStreamReader,但它不如TStringList 快,而且这个过程的持续时间是这个功能最关心的问题。

我正在使用 10.1 Berlin,解析过程是一个简单的迭代,通过不同长度的线列表和基于线信息的对象构造。

本质上,我的问题是,是什么导致了这种情况,我该如何解决。我可以使用其他方式加载文件并读取其内容,但它必须与 TStringList 方法一样快(或更好)。

加载线程执行代码:

TThreadFactory= class(TThread)
  protected
     // Class that holds the list of Commands already parsed, is owned outside of the thread
    _logFile: TLogFile;
    _criticalSection: TCriticalSection;
    _error: string;

    procedure Execute; override;
    destructor Destroy; override;

  public
    constructor Create(AFile: TLogFile; ASection: TCriticalSection); overload;

    property Error: string read _error;

  end;

implementation


{ TThreadFactory}

    constructor TThreadFactory.Create(AFile: TLogFile; …
Run Code Online (Sandbox Code Playgroud)

delphi tstringlist text-files delphi-10.1-berlin

0
推荐指数
1
解决办法
702
查看次数

仅按下CTRL键时移位值?

创建一个VCL Forms应用程序并在主窗体的OnMouseDown事件处理程序中写入:

procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Shift = [ssCtrl] then
    ShowMessage('CTRL pressed');
end;
Run Code Online (Sandbox Code Playgroud)

然后运行应用程序,按住CTRL键,没有其他修饰键,然后单击表单.没有显示任何消息.为什么现在?

那么Shift在这种情况下,当只按下CTRL键时,哪个值有效?

delphi modifier-key delphi-10.1-berlin

-1
推荐指数
1
解决办法
2373
查看次数

Delphi,在TPointerlist()中编辑tenumstring中的自动完成访问冲突

在@KenWhite的自动完成示例中,Next函数在TPointerList()[]调用时具有访问冲突(通过Windows自动完成界面).

D10.1u2,Win10.64

function TEnumString.Next(celt: Integer; out elt;
   pceltFetched: PLongint): HResult;
var
 I: Integer;
wStr: WideString;
begin
 I := 0;
 while (I < celt) and (FCurrIndex < FStrings.Count) do
   begin
     wStr := FStrings[FCurrIndex];
     TPointerList(elt)[1] := PWideChar('abcd');  //access violation
     TPointerList(elt)[1] := CoTaskMemAlloc(8);  //access violation
     TPointerList(elt)[I] := CoTaskMemAlloc(2 * (Length(wStr) + 1)); //access violation
     StringToWideChar(wStr, TPointerList(elt)[I], 2 * (Length(wStr) + 1));
     Inc(I);
     Inc(FCurrIndex);
  end;
 if pceltFetched <> nil then
  pceltFetched^ := I;
 if I = celt then
 Result := …
Run Code Online (Sandbox Code Playgroud)

delphi autocomplete delphi-10.1-berlin

-1
推荐指数
1
解决办法
130
查看次数

Delphi动态数组SetLength崩溃

我正在使用Delphi 10.1和Windows 10,包含所有最新更新.

我的应用程序使用并重新使用大量50个或更多的动态数组,每个数组最多包含5,000个元素.在执行期间,使用SetLength(thearray,0)或清除这些数组thearray:=nil.紧接着这个,分配一个新的大小SetLength(thearry,newsize).

对于大多数阵列,这很顺利.但偶尔,这些分配中的一个或另一个(每次程序运行时都是相同的)在没有例外或其他通知的情况下崩溃.崩溃可能发生在清除功能或大小调整功能上.必须使用程序管理器关闭程序,然后重新启动.

真正奇怪的是导致崩溃的数组可能会改变,具体取决于所使用的内存管理器 - 本机Delphi,ScaleMM2,FastMM4.在过去,我有时通过重命名数组来解决问题,但是在多次更改和重新编译之后,问题会不时弹回.

机器的RAM检查正常,问题在多台机器上仍然存在.

delphi delphi-10.1-berlin

-1
推荐指数
1
解决办法
244
查看次数

Winapi.ShlObj.SHGetFolderPath可重现的错误

使用此代码我得到一个AV:

uses
  Winapi.ShlObj;

function GetUserAppDataPath: string;
var
  ThisPath: PWideChar;
begin
  if Winapi.ShlObj.SHGetFolderPath(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, ThisPath) = S_OK then
    Result := string(ThisPath)
  else
    Result := '';
end;
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在Delphi 10.2 Tokyo中,如果我两次调用此函数,第二次获得AV.

是什么导致这个错误?

我曾经PWideChar因为德尔福IDE的告诉我的: 在此输入图像描述

delphi winapi delphi-10.1-berlin delphi-10.2-tokyo

-1
推荐指数
1
解决办法
127
查看次数

如何在TMemIniFile上对章节进行排序

我使用TMemIniFile来存储配置,我需要按照alpha顺序对这些部分进行排序.

为此,我创建了TMemIniFile的后代

  TRWStudioMemIniFile = class(TMemIniFile)
  public
    procedure UpdateFile; override;
    procedure GetSortedStrings(List: TStrings);
  end;


{ TRWStudioMemIniFile }

procedure TRWStudioMemIniFile.GetSortedStrings(List: TStrings);
var
  I, J: Integer;
  Strings: TStrings;
begin
  List.BeginUpdate;
  try
    Sections.Sort;
    for I := 0 to Sections.Count - 1 do
    begin
      List.Add('[' + Sections[I] + ']');
      Strings := TStrings(Sections.Objects[I]);
      for J := 0 to Strings.Count - 1 do List.Add(Strings[J]);
      List.Add('');
    end;
  finally
    List.EndUpdate;
  end;
end;

procedure TRWStudioMemIniFile.UpdateFile;
var
  List: TStringList;
begin
  List := TStringList.Create;
  try
    GetSortedStrings(List);
    List.SaveToFile(FileName, Encoding);
  finally
    List.Free;
  end;
end; …
Run Code Online (Sandbox Code Playgroud)

delphi oop delphi-10.1-berlin

-2
推荐指数
1
解决办法
319
查看次数