所以我正在使用 pascal,并且我想向一种情况添加多个语句。我尝试了这段代码,但收到错误:“错误:常量和 CASE 类型不匹配”
procedure pay;
begin
loop:=loop+1;
CASE loop OF
1:
writeln('E-Mail: ');
readln(mailO[1]);
writeln('amount: ');
readln(amount[1]);
end;
Run Code Online (Sandbox Code Playgroud) 我想知道docs 中描述的free pascal 函数中非常奇怪的行为。
据说,以下代码将成功编译/执行:
function Test : integer;
begin
Test := 2;
end;
begin
WriteLn(Test());
end.
Run Code Online (Sandbox Code Playgroud)
Test但是如果我在方程右侧使用函数名称,它将执行递归循环。
因此,pascal 函数从一方面来说,用变量的名称Test和函数返回值的类型来定义变量integer。从另一边,您仍然可以调用函数(使用其名称进行递归调用)。
为什么?!目标是什么?
两天前,我在 Free Pascal 编译器 2.2.0 中遇到以下错误:
Error: Invalid reference syntax
Run Code Online (Sandbox Code Playgroud)
史前史:
我想编译一个 pascal 源代码,其中包含一些适用于平台“i386-linux”的汇编指令
procedure drawpixel(x,y,color: word); assembler;
asm
mov ax, y
mov bx, x
mov dl, color
mov cx, 320
mul cx
add ax, bx
mov di, ax
mov [es:di], dl /// Right at [es:di] the inline assembler gives this annoying exception
ret
end;
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我吗?
我正在开发一个项目,需要非常有效地操作一组 32 位。内存效率至关重要,因此使用布尔数组(占用 32 个字节)不是一个选择(如果我可以有其他选择,速度是最重要的)。
这是我为 TBitSet32 设想的结构:
TBitSet32 = record
value: ?integer?; // I'm not sure about the datatype here. Should it be Integer or another type?
// Gets the value associated with a particular bit index.
function valueForBit(index: integer): boolean;
// Returns the number of marked bits in the set.
function count: integer;
// Marks the specified bit.
procedure markBit(value: boolean; index: integer);
end;
Run Code Online (Sandbox Code Playgroud)
对于值字段,我认为我需要 32 位整数类型。Integer 这里的选择正确吗?如何实现 valueForBit、count 和 markBit 方法?
对于此记录的任何见解或示例实现,我将不胜感激。
我有一个应用程序,我需要在Linux上移植.我正在考虑使用Free Pascal,问题是应用程序使用Windows API来执行串口通信等任务...是否有一个msdn for linux用户或一本书,涵盖了如果有apis linux如何工作.
我很迷茫.
我想编写一个函数GenString,它[0 .. 100]根据GenChar用户可以自定义的参数化函数返回一个随机字符串长度.
也就是说,如果一个用户想要生成所有as 的字符串,他可以通过传入一个总是返回的函数来做到这一点a,而另一个用户可以通过传入一个GenChar返回随机希伯来字母的自定义函数来生成随机字母希伯来语单词.
引理1:我想编写一个函数GenArray,生成一个传入函数GenThing : sometype返回的任何类型的数组.这可以在Free Pascal中完成.
引理2:我要做的是将QuickCheck移植到Free Pascal.
我正在Pascal的小型项目上学.我正在使用Lazaruz 1.0.2
写入文件时,我遇到了wirteLn函数的问题.一段时间后,它只是停止写入文件.
以此程序为例:
var oFile: Text;
i: LongWord;
begin
Assign(oFile, 'test.txt');
ReWrite(oFile);
for i:=1 to 4096 do
WriteLn(oFile, 'ThisIsTest');
CloseFile(oFile);//Added as suggested
end.
Run Code Online (Sandbox Code Playgroud)
这是输出:
...
4072 ThisIsTest
4073 ThisIsTest
4074 ThisIsTest
4075 ThisIsTe
Run Code Online (Sandbox Code Playgroud)
正如你所看到的那样,它只是在句子的中间停止而且并不是全部写的.所有这些都取决于一个WriteLn insturction的持续时间和调用次数.
怎么解决?
我尝试使用名为WriteFile的"Windows"模块中的WinApi函数,但是我没能将最后3个参数传递给它.
大新闻
谢谢.这个例子中有效(关闭文件).但是我有一些更复杂的程序,我将打开的文件句柄传递给通过"var"写入它的函数.即使在关闭该文件后也没有做任何事情.它很奇怪.
如果我想限制可以同时在词典中完成的线程查找的数量,该怎么做?并让线程睡眠,直到他们可以访问词典.即.如果两个查找已经在并行中进行,则其他查找必须等待,直到LookupCount小于2才能执行.
TLexicon
MaxLookups: Integer;
LookupCount: Integer;
Run Code Online (Sandbox Code Playgroud)
除了TLexicon之外,我创建了TLookupJob,它可以在TLookupThread中执行.LookupJob.Execute过程调用词典上的查找并等待直到有响应.
因此,LookupThreads必须睡眠,直到Lexicon.LookupCount小于Lexicon.MaxLookups.为此,我在LookupJob.Execute中调用GoSleep(事件),并且LookupThread的执行停止.但是如何以及何时发出信号.其余的设计对我来说还不清楚.
这里可以使用什么设计?
到目前为止,我已经创建了许多类:
TLexicon - 具有MaxLookups和LookupCount,以及查找功能.
LookupItem - 包含LookupWord和Response.传递给Lexicon.Lookup.
TLookupJob - 具有执行过程,以及GoSleep使用事件进行睡眠的WakeUp过程.
LookupThread - 执行LookupJob
随意改变设计.
是否有内置函数将整数转换为Free Pascal中的字符串,如返回整数输入的字符串对象?我已经为谷歌和文档提供了2个小时的能力,并且只找到了虚假的希望和失望.在Windows 10上使用Lazarus 1.4.4.
另外,为什么帕斯卡如此复杂/加重?有大量的版本,IDE,应用程序支持与非应用程序支持,文档最好是平庸(至少对于Free Pascal,尽管Delphi看起来也不是很好看).它遍布整个地方,就像一对巨大的纠结耳塞.
谢谢!
我用StringGrid绿色填充单元格
procedure TForm1.StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
StringGrid.Canvas.Brush.Color := clGreen;
StringGrid.Canvas.FillRect(Rect);
StringGrid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, AGrid.Cells[ACol, ARow]);
end;
Run Code Online (Sandbox Code Playgroud)
我的StringGrid有黑色.我想填充单元格透明色(例如50%).
我怎样才能做到这一点?
我应该绘制矩形?或者我应该创建位图并放入单元格?
你能帮助我吗?:)
freepascal ×10
pascal ×6
lazarus ×4
delphi ×3
assembly ×1
dynamic ×1
i386 ×1
linux ×1
porting ×1
random ×1
string ×1
stringgrid ×1
turbo-pascal ×1