forked from hartmutdavid/python4delphi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunMisc.pas
More file actions
87 lines (71 loc) · 1.97 KB
/
Copy pathunMisc.pas
File metadata and controls
87 lines (71 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
unit unMisc;
interface
uses Classes, Grids;
function ReadInteger( S : TStream ) : Integer;
procedure WriteInteger( S : TStream; val : Integer );
function ReadBoolean( S : TStream ) : Boolean;
procedure WriteBoolean( S : TStream; val : Boolean );
function ReadString( S : TStream ) : String;
procedure WriteString( S : TStream; val : String );
procedure RemoveLine( sg : TStringGrid; idx : Integer );
function AppendSlash( const str : String ) : String;
implementation
/////////////////////////////////////////
// Misc functions
/////////////////////////////////////////
function ReadInteger( S : TStream ) : Integer;
begin
S.Read( Result, Sizeof(Result) );
end;
procedure WriteInteger( S : TStream; val : Integer );
begin
S.Write( val, Sizeof(val) );
end;
function ReadBoolean( S : TStream ) : Boolean;
begin
S.Read( Result, Sizeof(Result) );
end;
procedure WriteBoolean( S : TStream; val : Boolean );
begin
S.Write( val, Sizeof(val) );
end;
function ReadString( S : TStream ) : String;
var
len : Integer;
begin
len := ReadInteger(S);
SetString(Result, PChar(nil), len);
S.Read(Pointer(Result)^, len);
end;
procedure WriteString( S : TStream; val : String );
begin
WriteInteger( S, Length(val) );
S.Write(Pointer(val)^, Length(val));
end;
procedure RemoveLine( sg : TStringGrid; idx : Integer );
var
i, j : Integer;
begin
with sg do
begin
if idx >= RowCount - 1 then
Exit;
Objects[0,idx].Free;
Objects[0,idx] := nil;
for i := idx+1 to RowCount - 1 do
for j := 0 to ColCount - 1 do
begin
Cells[j, i-1] := Cells[j, i];
Objects[j, i-1] := Objects[j, i];
end;
RowCount := RowCount - 1;
end;
end;
function AppendSlash( const str : String ) : String;
begin
if (Length(str)>0) and (str[Length(str)]<>'\') then
Result := str + '\'
else
Result := str;
end;
end.