我只是想从指定的文本文件中删除前N个字符,但我卡住了.请帮帮我!
procedure HeadCrop(const AFileName: string; const AHowMuch: Integer);
var
F: TextFile;
begin
AssignFile(F, AFileName);
// what me to do next?
// ...
// if AHowMuch = 3 and file contains"Hello!" after all statements
// it must contain "lo!"
// ...
CloseFile(F);
end;
Run Code Online (Sandbox Code Playgroud)
我试图使用TStringList,但它还附加了行尾字符!
with TStringList.Create do
try
LoadFormFile(AFileName); // before - "Hello!"
// even there are no changes...
SaveToFile(AFileName); // after - "Hello!#13#10"
finally
Free;
end;
Run Code Online (Sandbox Code Playgroud)
谢谢!
procedure questiontype;
begin
writeln ('Enter the type of question you would like...');
writeln ('1. Add');
writeln ('2. Multiply');
writeln ('3. Subtraction');
writeln ('4. Division');
readln (typeofquestion);
case typeofquestion of
1: add;
2: multiply;
3: subraction;
4: division
else writeln ('Choose again');
end;
end;
Run Code Online (Sandbox Code Playgroud)
所有程序都是加法,乘法,减法和除法.如果我把它放在主程序中,它将工作正常,但当我把它作为一个程序本身,我得到错误未声明的标识符.我在许多网站上看过一个这样的例子,但我找不到任何网站.
make add,multiply,subtraction,division如何从这个内部进入程序?
只是试图在ObjectPascal/Delphi中实现C/C++静态局部变量的类似功能.我们在C中有以下功能:
bool update_position(int x, int y)
{
static int dx = pow(-1.0, rand() % 2);
static int dy = pow(-1.0, rand() % 2);
if (x+dx < 0 || x+dx > 640)
dx = -dx;
...
move_object(x+dx, y+dy);
...
}
Run Code Online (Sandbox Code Playgroud)
使用类型常量作为静态变量替换的等效ObjectPascal代码无法编译:
function UpdatePosition(x,y: Integer): Boolean;
const
dx: Integer = Trunc( Power(-1, Random(2)) ); // error E2026
dy: Integer = Trunc( Power(-1, Random(2)) );
begin
if (x+dx < 0) or (x+dx > 640) then
dx := -dx;
...
MoveObject(x+dx, y+dy);
...
end; …Run Code Online (Sandbox Code Playgroud) 我正在使用旧式Pascal I/O例程,并期望对失败的I/O函数的调用应该引发EInOutError.当我尝试这个时,我没有看到异常提出,我不知道为什么.
procedure TForm1.Button1Click(Sender: TObject);
//var i: integer;
begin
id:=(strtoint(Edit1.Text)-1)*4;
AssignFile(plik,'\klienci\'+linia_klient[id]+'.txt');
try
Reset(plik);
except
on EInOutError do Rewrite(plik);
end;
edit2.Text:=linia_klient[id+1];
edit3.Text:=linia_klient[id+2];
//ListBox1.Clear;
//ListBox1.Items.Add();
end;
Run Code Online (Sandbox Code Playgroud)
整个代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Label2: TLabel;
Label3: TLabel;
Edit2: TEdit;
Edit3: TEdit;
ListBox1: TListBox;
Label4: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; …Run Code Online (Sandbox Code Playgroud) 你好,我最近换TextFile了TFileStream.我从不使用它,所以我的问题很小.
我需要定义的行格式文件,所以我做的是这样的:
var linia_klienta:array[0..30] of string;
AssignFile(tempPlik,'klienci.txt');
Reset(tempPlik);
i:=0;
While Not Eof(tempPlik) do
begin
Readln(tempPlik,linia_klient[i]);
inc(i);
end;
CloseFile(tempPlik);
Run Code Online (Sandbox Code Playgroud)
然后当我需要第二行时
edit1.text = linia_klienta[1];
Run Code Online (Sandbox Code Playgroud) 我正在构建一个进行科学模拟的delphi应用程序.它的复杂程度越来越高,现在由许多单位和形式组成.
我每次跑步时都会开始出现EOutOFMemory错误.它似乎发生在我在函数中临时使用变量数组期间或之后.有可能提出一个非常愚蠢的问题,是"变种阵列"要求麻烦吗?(我可以将所有内容转换为字符串,但原则上的变体数组可以节省很多捏造的东西).
有问题的数组使用可能是:
Function TProject.GetCurrentProjParamsAsArray(LProjectName, LProjectType : ShortString): ArrayOfVariant;
Var
ArrayIndex : Word;
begin
SetLength (Result,54);
ArrayIndex := 0;
Result [ArrayIndex] := LProjectName; Inc(ArrayIndex);
Result [ArrayIndex] := LProjectType; Inc(ArrayIndex); // this structure makes it easier to add extra fields in the DB than hard coding the array index!!
Result [ArrayIndex] := FileTool.DateTimeForFileNames ; Inc(ArrayIndex);
Result [ArrayIndex] := SiteAndMet. SiteName ; Inc(ArrayIndex);
Result [ArrayIndex] := SiteAndMet. PostCode ; Inc(ArrayIndex);
Result [ArrayIndex] := SiteAndMet. MetFileNamePath ; Inc(ArrayIndex);
Result [ArrayIndex] := SiteAndMet. SiteLat …Run Code Online (Sandbox Code Playgroud) 我想知道如何在trackbar1.position的相反方向上制作我的第二个trackbar.position镜像.例如.范围从1到100.
所以什么时候TrackBar1.Position := 2,然后trackbar2.Position := 99
无论轨道轨道走哪条路,我都想反映相反的方向.
到目前为止,我的代码是:(对使用密钥不感兴趣),只是鼠标交互.
Direction : string;
Skip : boolean;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
if TrackBar1.Position = TrackBar2.Position then
begin
if Direction = 'up' then TrackBar2.Position := TrackBar2.Position + 1;
if Direction = 'down' then TrackBar2.Position := TrackBar2.Position - 1;
skip := true;
end;
if TrackBar1.Position < TrackBar2.Position then
begin
if skip = false then
begin
TrackBar2.Position := TrackBar2.Position - 1;
Direction := 'down';
end;
end
else
begin
if skip = false then …Run Code Online (Sandbox Code Playgroud) 我是初学者Pascal程序员,最近我迁移到了Mac OS X.今天我花了很多时间为这个操作系统寻找一个好的Pascal IDE,却一无所获.我以前在Windows上用Geany编写代码,它就像一个魅力,我也很喜欢Geany的编译和运行能力.
你知道任何类似Geany的IDE或至少一个在Mac OS X上突出显示,编译和运行pascal代码的IDE吗?
非常感谢你!
如何使用该writeln函数在Pascal中打印撇号?
例:
writeln('My brother's book');
Run Code Online (Sandbox Code Playgroud)
因为s book超出"写入"功能而无法工作,因此编译器返回错误:
Fatal: Syntax error, ")" expected but "identifier S" found
Fatal: Compilation aborted
Run Code Online (Sandbox Code Playgroud) 考虑一下代码:
procedure DoSmthSecret;
var
Seed: array[0..31] of Byte;
begin
// get random seed
..
// use the seed to do something secret
..
// erase the seed
FillChar(Seed, SizeOf(Seed), 0);
end;
Run Code Online (Sandbox Code Playgroud)
代码的问题是:FillChar是编译器内在的,并且编译器可能会"优化它".问题是C/C++编译器所知,请参阅SecureZeroMemory.现代Pascal编译器(Delphi,FPC)可以进行这样的优化,如果可以的话,它们是否提供了与SecureZeroMemory等效的?
pascal ×10
delphi ×8
fpc ×1
freepascal ×1
ide ×1
macos ×1
procedure ×1
text-files ×1
trackbar ×1
vcl ×1