Borland Pascal 7 和 Delphi 2007 都得到了过程 STR,它接受一个数字、一个长度和一个精度,并将其转换为这样的字符串:
str(9.234:5:1, s); // -> s = ' 9.2'
Run Code Online (Sandbox Code Playgroud)
如果舍入是非歧义的,一切都很好,但如果不是(0.5 -> 向上或向下?),则存在问题:它似乎取决于 BP 中的浮点数据类型,但在 Delphi 2007 中显然是一致的:
BP:
var
e: extended;
d: double;
begin
d := 2.15;
e := 2.15;
str(d:5:1, s); { -> s = ' 2.1' }
str(e:5:1, s); { -> s = ' 2.2' }
{ but: }
d := 2.25
e := 2.25
str(d:5:1, s); { -> s = ' 2.3' }
str(e:5:1, s); { -> s = ' …Run Code Online (Sandbox Code Playgroud) 我正在对一个 18 岁的 pascal 程序进行维护。为了帮助我理解一切是如何组合在一起的,我想绘制一个调用图。但是我找不到任何可以为 pascal 源绘制调用图的软件。我目前正在使用 Turbo Pascal 7 并且不知道其他 pascal 编译器的能力。
我在Pascal中找了很长时间这个算法并没有找到,我发现它只在C++中,它令人沮丧.然后我决定翻译Pascal的C++代码,但是有些问题我无法解决.它出现了错误消息"浮点溢出".我想帮助使这段代码有效!
var
WFX: pWaveFormatEx;
{** Algoritimo Pitch Shift **}
gInFIFO, gOutFIFO, gLastPhase, gSumPhase, gOutputAccum: Array Of Extended;
gAnaMagn, gAnaFreq, gSynFreq, gSynMagn, gFFTworksp: Array Of Extended;
Const
MAX_FRAME_LENGTH = 8192;
implementation
{$R *.dfm}
procedure smbFft(fftBuffer: PExtended; fftFrameSize, sign: Integer);
var
p1, p2, p1r, p1i, p2r, p2i: PExtended;
wr, wi, arg, temp: EXTENDED;
tr, ti, ur, ui: EXTENDED;
i, bitm, j, le, le2, k: Integer;
begin
i:= 2;
WHILE (i < 2*fftFrameSize-2) DO //for (i = 2; i < 2*fftFrameSize-2; i += …Run Code Online (Sandbox Code Playgroud) 我只是想知道如何在pascal中进行类型检查?我已经搜寻了几个小时,但找不到任何有用的东西。
例:
var
number: Integer;
begin
write('Enter a number: ');
read(number);
if {How am I supposed to check if 'number' is an Integer here?}
then writeln(number)
else writeln('Invalid input')
end.
Run Code Online (Sandbox Code Playgroud) 尽管Delphi引用了什么
结构化类型可以包含其他结构化类型 一个类型可以有无限级别的结构
值得注意的例外是结构化类型常量
不能包含任何级别的文件类型值
我发现我不能使用记录常量作为相同类型的数组常量的元素.
type
MyRecord = record MyField: Integer end;
const
Typical: array[0..1] of MyRecord = ((MyField: 0), (MyField: 1));
{ now I tried to achieve more clarity by declaring a specific constant }
Zero: MyRecord = (MyField: 0);
{ and compiler refused to accept that }
Bad: array[0..1] of MyRecord = (Zero, (MyField: 1)); { E2029 '(' expected but identifier 'Zero' found }
Run Code Online (Sandbox Code Playgroud)
我用几个Borland编译器测试了这个代码,它们都表现出相同的行为.UPD:FPC也是如此,但不适用于GPC(!).
这里发生了什么?我是否更正问题标题中的"嵌套结构类型的嵌套常量不受支持"结论?对问题的任何更多分析?
我一直在学习Pascal(使用Free Pascal编译器)一个星期,并且遇到了一个看似简单的练习.给定如下所示的结构,找到最大加权分支:
1
4 9
7 0 2
4 8 6 3
Run Code Online (Sandbox Code Playgroud)
分支是从顶部开始的任何数字序列(在这种情况下:1),对于每个数字,分支可以向左或向右扩展.例如,分支1-4-0可以扩展为1-4-0-8或1-4-0-6.所有分支必须从顶部开始,在底部结束.
在这个例子中,最大分支是1-4-7-8,这给了我们20.为了解决这个问题,我尝试使用回溯.三角形结构存储在"三角形"类型的数组中:
type triangle = array[1..MAX_NUM_OF_ROWS, 1..MAX_NUM_OF_ROWS] of integer;
Run Code Online (Sandbox Code Playgroud)
这是我的实现:
function findAux(data: triangle; dim: integer; i: integer; j:integer) : integer;
begin
if i = dim then
findAux := data[i][j]
else
if findAux(data, dim, i + 1, j + 1) > findAux(data, dim, i + 1, j) then
findAux := data[i+1][j+1] + findAux(data, dim, i + 1, j + 1);
else
findAux := data[i+1][j] + findAux(data, dim, i + …Run Code Online (Sandbox Code Playgroud) 我有一个 Inno Setup 安装程序,需要在安装过程中进行 API 调用。这会将一些数据发布到远程 API。
POST 调用在 [Code] 部分使用 Pascal 和WinHttpRequest对象执行。API 是 ASP.Net WebAPI 2 (C#)。
我可以完全控制流程的所有部分,即 Inno Setup 脚本、代码部分和 WebAPI。
我可以在没有任何问题的情况下同步进行 POST 调用,但是如果我true在WinHttpRequest.Open()方法上设置 async 标志,则该.Send()方法似乎根本不会执行。
procedure PostData(postural: String);
var
WinHttpReq: Variant;
ReqContent: String;
begin
try
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
ReqContent := 'item=value';
WinHttpReq.Open('POST', postUrl, true);
WinHttpReq.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
WinHttpReq.Send(ReqContent);
except
end;
end;
Run Code Online (Sandbox Code Playgroud)
我在 VisualStudio 调试器中检查了一个断点,并且永远不会调用端点。
在此处和 Google 上搜索时,我只发现了各种异步获取响应的尝试,但我找不到针对此问题的解决方案。我不需要响应,这是一种即发即忘的 API 调用。
为什么 API 没有收到调用,我该如何解决这个问题?
谢谢。
I'm implementing a Pascal parser from this EBNF defintion. There is something I don't understand in the following specifications:
variable
entire-variable | component-variable | referenced-variable
entire-variable
variable-identifier | field-identifier
component-variable
indexed-variable | field-designator | file-buffer
field-designator
record-variable "." field-identifier
Run Code Online (Sandbox Code Playgroud)
Assume we want to apply the variable production on a.b[0]. Since a conforms to the entire-variable production, this will prevent component-variable from detecting the field-designator a.b and therefore the . following a will stop the parser.
为什么 pascal 在 (8,21) 和 (8,12) 行中给了我无法访问的代码。我不知道为什么它是一个将 3 位八进制数转换为十进制的简单代码。该程序没问题,因为它给了我正确的结果,但我不知道为什么 free pascal 在程序的那个部分给了我无法访问的代码。
我在 Linux 上使用 3.0.4 freepascal,我只使用我发布的命令进行编译,我没有修改 freepascal 的任何内容我使用以下命令进行编译 fpc -Co -Cr -Miso -gl
PROGRAM Ejercicio21;
VAR decimal,octal,a,b,c:integer;
BEGIN
writeln('Ingrese el valor decimal: ');
readln(octal);
a:=(octal div 100);
b:=(octal mod 100) div 10;
c:=octal mod 10;
decimal:=(a*sqr(8)+(b*8)+c);
writeln('Octal',octal,'=',decimal);
END.
Run Code Online (Sandbox Code Playgroud) pascal ×10
delphi ×3
freepascal ×3
backtracking ×1
call-graph ×1
delphi-2007 ×1
ebnf ×1
fpc ×1
http ×1
inno-setup ×1
post ×1
recursion ×1
rounding ×1
turbo-pascal ×1