小编Mik*_*mik的帖子

显示异步“等待”窗口

在 Delphi VCL 应用程序中,我想在执行一个耗时的过程时创建一个“等待”消息窗口(本例中是一个大循环)。

在开始耗时的过程之前,我已经尝试了以下要执行的事情。

- 创建一个包含消息的简单窗口的新形式。

- 使用 messagedlg 创建消息。

- 甚至更改主窗体上的 TLabel.Caption (执行耗时过程的那个)。

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
  popUpMessage;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;

    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;
  dialog : TForm;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
    var i, j, k :LongInt;
begin


     {1}
     popUpMessage.Form2 := TForm2.Create(nil); //also tried with Create(self)
     Form2.show;

     {2}
     dialog := CreateMessageDialog ('Wait',TMsgDlgType.mtWarning, mbYesNoCancel);
     dialog.Show;


     {3}
     messagedlg('Wait',mtError, mbOKCancel, 0); …
Run Code Online (Sandbox Code Playgroud)

delphi asynchronous non-modal

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

如何删除使用 _strdup() 创建的 const char*

我在 Visual Studio 中使用以下代码来存储构造函数参数 char* 并在我的类的解构中将其删除。

#include "pch.h"
#include <iostream>

class A
{
public:
    A(const char *fn) {
        myChar = _strdup(fn);
    }

    ~A() {
        delete[] myChar;
    }

    char *myChar;
};


int main()
{
    A myA("lala");
    myA.~A();

    _CrtDumpMemoryLeaks(); //leak detector
}
Run Code Online (Sandbox Code Playgroud)

如果我不使用 delete[] myChar,则会造成内存泄漏。如果我使用它,我会在调试时遇到这个未知错误。

在此处输入图片说明

这样做的正确方法是什么?


更改delete[]为 后free

https://i.stack.imgur.com/VIbNo.png

c++ memory memory-leaks char

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

如何读取大小未知的未知类型文件

我需要读取未知类型和大小的文件的内容,并将其临时保存(以某种变量),因此稍后将其用于通过串行端口进行传输。据我了解,TFileStream是正确的方法。

我确实尝试从http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/TReader_(Delphi)实现以下教程

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Utils;

type
  TForm1 = class(TForm)
    procedure OnCreate(Sender: TObject);

    private
      selectedFile: string;
  end;

var
  Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.OnCreate(Sender: TObject);
  function ReadFileContent(fileName: String): String;
  var
    FileStream: TFileStream;
    Reader: TReader;
    tByte :byte;

  begin

    FileStream := TFileStream.Create(fileName, fmOpenRead);
    Reader := TReader.Create(FileStream, $FF);

    Reader.ReadListBegin;           //I get 'Invalid property Value' error
                                    //in this line raised from the Reader object

    while not Reader.EndOfList do
    begin
      Reader.ReadVar(tByte, …
Run Code Online (Sandbox Code Playgroud)

delphi tfilestream

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