标签: freepascal

Lazarus - 为什么我不能将事件分配给运行时组件?

我有这个Lazarus计划:

unit Unit2; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  StdCtrls, ComCtrls;

type

  { TForm2 }

  TForm2 = class(TForm)
    procedure OnTlacitkoClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    tlac:TButton;
  private
    { private declarations }
  public
    { public declarations }
  end;



var
  Form2: TForm2;

implementation

{ TForm2 }

procedure TForm2.OnTlacitkoClick(Sender: TObject);
begin
  showmessage('helloworld');
end;

procedure TForm2.FormCreate(Sender: TObject);
var i,j:integer;
begin
  tlac:=TButton.Create(Form2);
  tlac.OnClick:=OnTlacitkoClick;
  tlac.Parent:=Form2;
  tlac.Left:=100;
  tlac.Top:=100;
end;

initialization
  {$I unit2.lrs}

end.
Run Code Online (Sandbox Code Playgroud)

但编译器说:unit2.pas(63,32)错误:在tlac.OnClick中调用"OnTlacitkoClick"时指定的参数数量错误:= OnTlacitkoClick; 表达.我搜索并认为这是德尔福的法律表达.我想简单地将OnTlacitkoClick注册为tlac.OnClick事件,而不是调用此过程.是否有一些错误的代码或我必须在Lazarus/Freepascal做不同的? …

events pascal freepascal onclick lazarus

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

如何在 FreePascal 中正确传递动态数组

在我编写的这个 FreePascal 代码中,我发现在一个长度为“n”的动态数组中,它总是在元素“n”中包含一个随机值。

我理解为什么会这样,但是,我想知道我编写代码的方式是否存在缺陷。我把它粘贴在下面。我欢迎任何更正。

program LinearSearch;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils
  { you can add units after this };

{$R *.res}

type
  ArrayOfByte = array of Byte;

Function findMaximum(studentMarks : ArrayOfByte; numberOfStudents : integer)
: integer;
var
  maximumMark : Integer;
  studentWithMaximumMark : Integer;
  index : integer;
begin
  setLength(studentMarks, numberOfStudents);
  maximumMark := studentMarks[0];

  for index:=0 to numberOfStudents do
  begin
    write(IntToStr(studentMarks[index]));
    if index = numberOfStudents then writeln('.')
    else write(',');
  end;

  for index:= 0 to (numberOfStudents - 1) …
Run Code Online (Sandbox Code Playgroud)

freepascal parameter-passing dynamic-arrays

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

为什么我的StringGrid在成千上万的条目后似乎变慢了?免费Pascal

我用Free Pascal和Lazarus IDE编写了一个程序.简而言之,它递归扫描每个文件的目录和'做东西'(散列),然后将散列值和文件名输出到StringGrid中,并使用每个连续文件刷新.

它适用于多达几千个文件,但是当你达到数万个时,它确实变慢,每半秒处理一个文件,即使它只是一个几Kb的小文件.

责任代码的主要部分如下.任何人都可以看到为什么我的程序在网格中的文件数量超过数万时会变慢?

procedure TForm1.HashFile(FileIterator: TFileIterator);
var
  SizeOfFile : int64;
  NameOfFileToHash, fileHashValue, PercentageProgress : string; 
  FI : TFileIterator;                      //File Iterator class
  SG : TStringGrid;

begin
  FI := TFileIterator.Create;
  SG := TStringGrid.Create(self);
  SizeOfFile := 0;
  fileHashValue := '';

  if StopScan = FALSE then                     // If Stop button clicked, cancel scan
    begin
    NameOfFileToHash := (FileIterator.FileName);
    SizeOfFile := FileSize(NameofFileToHash);
    StatusBar1.SimpleText := 'Currently Hashing: ' + NameOfFileToHash;
    fileHashValue := CalcTheHashFile(NameOfFileToHash); // Custom function, see below

    // Now lets update the stringgrid and …
Run Code Online (Sandbox Code Playgroud)

freepascal lazarus

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

Lazarus/Delphi - 单击项目的indext /元素(控制数组)

我在表单上有一组PANEL,它们用作按钮.分配了一个事件过程.所以当我点击一个按钮时,我可以看到它的标题:

procedure TForm1.MenuAction0Click(Sender: TObject);
begin
  TPanel(Sender).Font.Bold:= true;
  ShowMessage( TPanel(Sender).Caption);

end;
Run Code Online (Sandbox Code Playgroud)

我想知道按钮编号(如数组元素编号)而不是标题.这怎么可能?

谢谢!

delphi control-array element freepascal lazarus

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

函数编译并处理一些数据而不是其他数据?

我的程序的一部分从char类型的缓冲区读取ASCII文本,它本身可以包含一些不可打印的非ASCII垃圾.当显示这些区域时,例如in ShowMessage(strVar),如果有空字符(0x00),则不显示该字符串,即使其中有可打印文本也是如此.

所以我写了这个小函数(我试图养成为这些技巧编写函数的习惯,但仍然不是很擅长)来清理任何不可打印的空字符的变量:

// FUNCTION RemoveNullChars : Removes 0x00 from strings, which cause empty string
// fields if not removed sometimes

function TForm1.RemoveNullChars(strValue: string): String;
var
  i : integer;
  NullChar : char;

begin
  NullChar := Chr($00);
  for i := 0 to Length(strValue) do
    begin
    if strValue[i] = NullChar then
      strValue[i] := ' ';
    end;
result := strValue;
end;   
Run Code Online (Sandbox Code Playgroud)

它编译好,实际上在一些缓冲段上工作......它确实剥离了空格,但并不总是如此.其他时候,使用不同的数据源(但时间类型的数据源),我收到此错误:

在此输入图像描述

我无法弄清楚为什么它编译好然而实际上对某些数据运行正常但对其他数据没有效果?

delphi freepascal lazarus

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

divpd无法识别的操作码x64

我已经为矩阵操作创建了一个非常好的汇编程序库,最初用于Delphi 2007+.

这段代码在Delphi下工作得很好,所以我也想支持Freepascal,直到我在一行上遇到汇编语法错误,我才走得很远:

divdp xmm1,[r9 + rax - 112];

Freepascal(实际上是Lazaraus)报告错误:无法识别的opcoded DIVP

我有点困惑,因为这是一个标准的汇编程序指令......任何人都知道如何"教"Freepascal来理解这种类型的指令?

(注意我不想介绍任何db指令......)

delphi assembly freepascal

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

子阵列的最大值

是否有任何函数从longint数组的子数组返回最大数字?

例如:

我有阵列:[2,3,6,2,9,4,2,4]

我想要数组的前5个元素[2,3,6,2,9]的最大值(9)

哪个是最好的解决方案?

arrays pascal freepascal max

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

线程安全测试/减少

此代码线程是否安全,或者在执行InterLockedDecrement之前是否可以通过另一个线程更改FCount?

procedure TMyObject.Wait;
begin
  if FCount > 0 then
    InterLockedDecrement(FCount);
  ..
end;
Run Code Online (Sandbox Code Playgroud)

delphi multithreading freepascal lazarus

0
推荐指数
2
解决办法
137
查看次数

如何在Pascal中使用具有不同数据类型的多个参数来实现功能?

我已经用两个具有相同数据类型的参数制作了一个函数,对此我没有任何问题。

但是我在使用不同的数据类型时遇到了麻烦

这是我的代码:

uses crt;
function inputscore(name : string, score:integer) : integer;

begin
     writeln('My name is ',name,' and my score is ',score);
     inputscore:=0;
end;

begin
    clrscr;

    inputscore('David',98);
    readkey;
end.
Run Code Online (Sandbox Code Playgroud)

但是它返回了此错误消息:

multipleparameterfunc.pas(2,34)Fatal syntax error, ")" expected but "," found

pascal freepascal

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

C到Pascal类型转换

美好的一天,

我在Master(Raspberry pi 2B,使用Lazarus)和Slave - Arduino Nano之间进行I2C通信.在Arduino我定义了

 typedef union
 {
   float Temperature;
   uint8_t bytes[4];
 } floatuint;
 floatuint fu;
Run Code Online (Sandbox Code Playgroud)

我已经定义了覆盆子pi

 TFloatUint = packed record
   case Boolean of
     False: (dabDouble: Double);
     True: (dabByte: packed array[0..3] of cuint8);
 end;
Run Code Online (Sandbox Code Playgroud)

使用命令

 count := FpRead(I2DeviceHandle, fl.dabByte, 4);
Run Code Online (Sandbox Code Playgroud)

我收到字节数组的相同值,但fl.dabDouble显示不同的结果.

例如:

 fu.Temperature = 19.19;
 fu.bytes = (0, 128, 153, 65);

 fl.dabByte = (0, 128, 153, 65);
 fl.dabDouble = 2.6656892163191751e-314
Run Code Online (Sandbox Code Playgroud)

我犯了哪个错误?

c freepascal arduino raspberry-pi

0
推荐指数
2
解决办法
168
查看次数