列表6.9.txt
来自「klinux书籍的配套光盘。可以学习学习。」· 文本 代码 · 共 47 行
TXT
47 行
【列表6.9】摘录自PipeChildMain.pas的程序代码。
const
StrIndexLen = 4;
LF = ^J; { ASCII linefeed/newline }
var
PipeChildMainForm: TPipeChildMainForm;
ParentReadPipe : Integer;
SigActionRec : TSigAction;
implementation
{SR *.xfm}
procedure Handler(Sig : Integer); cdecl;
begin
case Sig of
SIGUSR1 : PipeChildMainForm. ReadPipe;
end; { case }
end;
procedure InstallHandler;
with SigActionRec do
begin
sigaction_handler := Handler;
sigemptyset(sa_mask);
sa_flags :=0;
sigaction(SIGUSR1, @SigActionRec, nil);
end; { with }
end;
procedure TPipeChildMainForm. ReadPipe;
var
ReadBuf : array[0..BUFSIZ] of Char;
s : String;
len : Integer;
begin
{ Get the length of the string }
_read(ParentReadPipe, ReadBuf, StrIndexLen);
ReadBuf[StrIndexLen] := chr(0);
len := StrToInt(ReadBuf);
{ Get the string }
read(ParentReadPipe, ReadBuf, len);
ReadBuf[len] := chr(0);
s := ReadBuf;
MsgMemo,Lines.Add(s);
end;
procedure TPipeChildMainForm. FormCreate(Sender: TObject);
begin
InstallHandler;
ParentReadPipe := StrToInt(ParamStr(1));
end;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?