Changeset 31
- Timestamp:
- Jun 24, 2010, 4:18:03 PM (14 years ago)
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
BitStream/UBitStream.pas
r30 r31 8 8 9 9 uses 10 Classes, SysUtils, RtlConsts ;10 Classes, SysUtils, RtlConsts, Math; 11 11 12 12 type … … 17 17 TBitStream = class 18 18 private 19 function GetBit(Index: Integer):Boolean; virtual; 19 20 function GetPosition: LongInt; virtual; 20 21 function GetSize: LongInt; virtual; 22 procedure SetBit(Index: Integer;const AValue: Boolean); virtual; 21 23 procedure SetPosition(const AValue: LongInt); virtual; 22 24 procedure SetSize(const AValue: LongInt); virtual; … … 30 32 property Position: LongInt read GetPosition write SetPosition; 31 33 property Size: LongInt read GetSize write SetSize; 34 property Bit[Index: Integer]: Boolean read GetBit write SetBit; 35 36 function ReadBit: Boolean; 37 procedure WriteBit(AValue: Boolean); 38 function ReadByte: Byte; 39 procedure WriteByte(AValue: Byte); 32 40 end; 33 41 … … 43 51 procedure SetPosition(const AValue: LongInt); override; 44 52 procedure SetSize(const AValue: LongInt); override; 53 function WriteToByte(var Data: Byte; NewData, Pos, Count: Byte): Byte; 45 54 public 46 55 function Read(var Buffer; Count: Longint): Longint; override; … … 56 65 { TBitStream } 57 66 67 function TBitStream.GetBit(Index: Integer):Boolean; 68 begin 69 Seek(Index, soBeginning); 70 Read(Result, 1); 71 end; 72 58 73 function TBitStream.GetPosition:LongInt; 59 74 begin … … 68 83 GetSize := Seek(0, soEnd); 69 84 Seek(p, soBeginning); 85 end; 86 87 procedure TBitStream.SetBit(Index: Integer;const AValue: Boolean); 88 begin 89 Seek(Index, soBeginning); 90 Write(AValue, 1); 70 91 end; 71 92 … … 123 144 end; 124 145 146 function TBitStream.ReadBit:Boolean; 147 begin 148 Read(Result, 1); 149 Result := Boolean(Integer(Result) and 1); 150 end; 151 152 procedure TBitStream.WriteBit(AValue:Boolean); 153 begin 154 Write(AValue, 1); 155 end; 156 157 function TBitStream.ReadByte:Byte; 158 begin 159 Read(Result, 8); 160 end; 161 162 procedure TBitStream.WriteByte(AValue:Byte); 163 begin 164 Write(AValue, 8); 165 end; 166 125 167 { TMemoryBitStream } 126 168 … … 143 185 begin 144 186 FSize := AValue; 145 Stream.Size := Trunc(AValue / 8) + 1; 187 Stream.Size := Ceil(AValue / 8); 188 if FPosition > FSize then FPosition := FSize; 189 end; 190 191 function TMemoryBitStream.WriteToByte(var Data: Byte; NewData,Pos,Count:Byte):Byte; 192 begin 193 Data := Byte(Data and not (((1 shl Count) - 1) shl Pos) // Make zero space for new data 194 or ((NewData and ((1 shl Count) - 1)) shl Pos)); // Write new data 195 Result := Count; 196 if Result > (8 - Pos) then Result := 8 - Pos; 146 197 end; 147 198 … … 153 204 Data: Byte; 154 205 begin 155 if (FPosition + Count) > FSize then Count := FSize - FPosition; 156 ByteCount := Trunc(Count / 8) + 1; 157 BytePos := FPosition mod 8; 158 Stream.Position := Trunc(FPosition / 8); 159 Data := Stream.ReadByte; 160 for I := 0 to ByteCount - 1 do begin 161 TBytes(Buffer)[I] := (Data shr BytePos) and ((1 shl (8 - BytePos)) - 1); 162 if I <> (ByteCount - 1) then 163 Data := Stream.ReadByte; 164 if BytePos > 0 then 165 TBytes(Buffer)[I] := TBytes(Buffer)[I] or (Data and ((1 shl BytePos) - 1)) shl (8 - BytePos); 166 if I = (ByteCount - 1) then 167 TBytes(Buffer)[I] := TBytes(Buffer)[I] and ((1 shl (Count mod 8)) - 1); 168 end; 169 Inc(FPosition, Count); 170 Result := Count; 206 Result := 0; 207 if (FSize > 0) and (FPosition < FSize) and (FPosition >= 0) then begin 208 if (FPosition + Count) > FSize then Count := FSize - FPosition; 209 ByteCount := Ceil(Count / 8); 210 BytePos := FPosition mod 8; 211 Stream.Position := Trunc(FPosition / 8); 212 Data := Stream.ReadByte; 213 for I := 0 to ByteCount - 1 do begin 214 TBytes(Buffer)[I] := (Data shr BytePos) and ((1 shl (8 - BytePos)) - 1); 215 if I <> (ByteCount - 1) then 216 Data := Stream.ReadByte; 217 if BytePos > 0 then 218 TBytes(Buffer)[I] := TBytes(Buffer)[I] or (Data and ((1 shl BytePos) - 1)) shl (8 - BytePos); 219 if (I = (ByteCount - 1)) and (BytePos > 0) then 220 TBytes(Buffer)[I] := TBytes(Buffer)[I] and ((1 shl (Count mod 8)) - 1); 221 end; 222 Inc(FPosition, Count); 223 Result := Count; 224 end; 171 225 end; 172 226 … … 174 228 var 175 229 ByteCount: LongInt; 230 BitCount: LongInt; 176 231 I: LongInt; 177 232 BytePos: Byte; 178 233 Data: Byte; 179 begin 180 ByteCount := Trunc(Count / 8) + 1; 234 function Min(Value1, Value2: Integer): Integer; 235 begin 236 if Value1 < Value2 then Result := Value1 else Result := Value2; 237 end; 238 239 begin 240 BitCount := Count; 241 ByteCount := Ceil(Count / 8); 181 242 BytePos := FPosition mod 8; 182 243 Stream.Position := Trunc(FPosition / 8); … … 186 247 end else Data := 0; 187 248 for I := 0 to ByteCount - 1 do begin 188 Data := (Data and ((1 shl BytePos) - 1)) or 189 ((TBytes(Buffer)[I] and ((1 shl (8 - BytePos)) - 1)) shl BytePos); 190 if I = (ByteCount - 1) then 191 Data := Data and ((1 shl (Count mod 8)) - 1); 249 Dec(BitCount, WriteToByte(Data, TBytes(Buffer)[I], BytePos, Min(8 - BytePos, BitCount))); 192 250 Stream.WriteByte(Data); 193 Data := (TBytes(Buffer)[I] shr (8 - BytePos)) and ((1 shl BytePos) - 1); 251 Data := 0; 252 if (BitCount > 0) and (BytePos > 0) then begin 253 if (I = (ByteCount - 1)) and (Stream.Position < Stream.Size) then begin 254 Data := Stream.ReadByte; 255 Stream.Position := Stream.Position - 1; 256 end; 257 Dec(BitCount, WriteToByte(Data, TBytes(Buffer)[I] shr (8 - BytePos), 0, Min(BytePos, BitCount))); 258 if I = (ByteCount - 1) then 259 Stream.WriteByte(Data); 260 end; 194 261 end; 195 262 Inc(FPosition, Count); … … 205 272 soCurrent: FPosition := FPosition + Offset; 206 273 end; 207 if FPosition > FSize then FPosition := FSize;274 //if FPosition > FSize then FPosition := FSize; 208 275 Result := FPosition; 209 276 end; -
BitStream/test.lpi
r30 r31 34 34 </local> 35 35 </RunParams> 36 <Units Count=" 5">36 <Units Count="7"> 37 37 <Unit0> 38 38 <Filename Value="test.lpr"/> 39 39 <IsPartOfProject Value="True"/> 40 40 <UnitName Value="test"/> 41 <IsVisibleTab Value="True"/> 41 42 <EditorIndex Value="0"/> 42 43 <WindowIndex Value="0"/> 43 <TopLine Value="42"/> 44 <CursorPos X="26" Y="56"/> 45 <UsageCount Value="20"/> 46 <Loaded Value="True"/> 44 <TopLine Value="54"/> 45 <CursorPos X="54" Y="59"/> 46 <UsageCount Value="23"/> 47 <Loaded Value="True"/> 48 <DefaultSyntaxHighlighter Value="Delphi"/> 47 49 </Unit0> 48 50 <Unit1> 49 51 <Filename Value="E:\Programy\Lazarus_0.9.29\fpc\2.4.1\source\packages\fcl-base\src\custapp.pp"/> 50 52 <UnitName Value="CustApp"/> 51 <EditorIndex Value=" 4"/>53 <EditorIndex Value="6"/> 52 54 <WindowIndex Value="0"/> 53 55 <TopLine Value="284"/> 54 56 <CursorPos X="3" Y="286"/> 55 <UsageCount Value="1 0"/>57 <UsageCount Value="11"/> 56 58 <Loaded Value="True"/> 57 59 </Unit1> … … 59 61 <Filename Value="UBitStream.pas"/> 60 62 <UnitName Value="UBitStream"/> 61 <IsVisibleTab Value="True"/>62 63 <EditorIndex Value="1"/> 63 64 <WindowIndex Value="0"/> 64 <TopLine Value=" 82"/>65 <CursorPos X=" 29" Y="85"/>66 <UsageCount Value="1 0"/>65 <TopLine Value="241"/> 66 <CursorPos X="45" Y="253"/> 67 <UsageCount Value="11"/> 67 68 <Loaded Value="True"/> 68 69 <DefaultSyntaxHighlighter Value="Delphi"/> … … 70 71 <Unit3> 71 72 <Filename Value="E:\Programy\Lazarus_0.9.29\fpc\2.4.1\source\rtl\objpas\classes\classesh.inc"/> 72 <EditorIndex Value=" 2"/>73 <WindowIndex Value="0"/> 74 <TopLine Value=" 778"/>75 <CursorPos X=" 1" Y="783"/>76 <UsageCount Value="1 0"/>73 <EditorIndex Value="4"/> 74 <WindowIndex Value="0"/> 75 <TopLine Value="868"/> 76 <CursorPos X="26" Y="876"/> 77 <UsageCount Value="11"/> 77 78 <Loaded Value="True"/> 78 79 </Unit3> 79 80 <Unit4> 80 81 <Filename Value="E:\Programy\Lazarus_0.9.29\fpc\2.4.1\source\rtl\objpas\classes\streams.inc"/> 82 <EditorIndex Value="5"/> 83 <WindowIndex Value="0"/> 84 <TopLine Value="532"/> 85 <CursorPos X="10" Y="544"/> 86 <UsageCount Value="11"/> 87 <Loaded Value="True"/> 88 </Unit4> 89 <Unit5> 90 <Filename Value="E:\Programy\Lazarus_0.9.29\fpc\2.4.1\source\rtl\inc\systemh.inc"/> 81 91 <EditorIndex Value="3"/> 82 92 <WindowIndex Value="0"/> 83 <TopLine Value=" 140"/>84 <CursorPos X=" 24" Y="166"/>93 <TopLine Value="813"/> 94 <CursorPos X="11" Y="827"/> 85 95 <UsageCount Value="10"/> 86 96 <Loaded Value="True"/> 87 </Unit4> 97 </Unit5> 98 <Unit6> 99 <Filename Value="E:\Programy\Lazarus_0.9.29\fpc\2.4.1\source\rtl\objpas\math.pp"/> 100 <UnitName Value="math"/> 101 <EditorIndex Value="2"/> 102 <WindowIndex Value="0"/> 103 <TopLine Value="310"/> 104 <CursorPos X="10" Y="326"/> 105 <UsageCount Value="10"/> 106 <Loaded Value="True"/> 107 </Unit6> 88 108 </Units> 89 109 <JumpHistory Count="30" HistoryIndex="29"> 90 110 <Position1> 91 111 <Filename Value="UBitStream.pas"/> 92 <Caret Line="1 58" Column="1" TopLine="141"/>112 <Caret Line="118" Column="1" TopLine="103"/> 93 113 </Position1> 94 114 <Position2> 95 115 <Filename Value="UBitStream.pas"/> 96 <Caret Line="1 59" Column="1" TopLine="141"/>116 <Caret Line="119" Column="1" TopLine="103"/> 97 117 </Position2> 98 118 <Position3> 99 119 <Filename Value="UBitStream.pas"/> 100 <Caret Line="1 60" Column="1" TopLine="141"/>120 <Caret Line="120" Column="1" TopLine="103"/> 101 121 </Position3> 102 122 <Position4> 103 123 <Filename Value="UBitStream.pas"/> 104 <Caret Line="1 61" Column="1" TopLine="141"/>124 <Caret Line="121" Column="1" TopLine="103"/> 105 125 </Position4> 106 126 <Position5> 107 127 <Filename Value="UBitStream.pas"/> 108 <Caret Line="1 62" Column="1" TopLine="141"/>128 <Caret Line="122" Column="1" TopLine="103"/> 109 129 </Position5> 110 130 <Position6> 111 131 <Filename Value="UBitStream.pas"/> 112 <Caret Line=" 163" Column="1" TopLine="141"/>132 <Caret Line="240" Column="1" TopLine="226"/> 113 133 </Position6> 114 134 <Position7> 115 135 <Filename Value="UBitStream.pas"/> 116 <Caret Line=" 165" Column="1" TopLine="142"/>136 <Caret Line="241" Column="1" TopLine="226"/> 117 137 </Position7> 118 138 <Position8> 119 139 <Filename Value="UBitStream.pas"/> 120 <Caret Line=" 161" Column="1" TopLine="142"/>140 <Caret Line="242" Column="1" TopLine="235"/> 121 141 </Position8> 122 142 <Position9> 123 143 <Filename Value="UBitStream.pas"/> 124 <Caret Line=" 162" Column="1" TopLine="142"/>144 <Caret Line="243" Column="1" TopLine="235"/> 125 145 </Position9> 126 146 <Position10> 127 147 <Filename Value="UBitStream.pas"/> 128 <Caret Line=" 161" Column="19" TopLine="142"/>148 <Caret Line="247" Column="1" TopLine="235"/> 129 149 </Position10> 130 150 <Position11> 131 151 <Filename Value="UBitStream.pas"/> 132 <Caret Line=" 165" Column="1" TopLine="142"/>152 <Caret Line="248" Column="1" TopLine="235"/> 133 153 </Position11> 134 154 <Position12> 135 155 <Filename Value="UBitStream.pas"/> 136 <Caret Line=" 161" Column="1" TopLine="142"/>156 <Caret Line="249" Column="1" TopLine="235"/> 137 157 </Position12> 138 158 <Position13> 139 159 <Filename Value="UBitStream.pas"/> 140 <Caret Line=" 162" Column="1" TopLine="142"/>160 <Caret Line="250" Column="1" TopLine="235"/> 141 161 </Position13> 142 162 <Position14> 143 163 <Filename Value="UBitStream.pas"/> 144 <Caret Line=" 163" Column="1" TopLine="142"/>164 <Caret Line="244" Column="1" TopLine="235"/> 145 165 </Position14> 146 166 <Position15> 147 167 <Filename Value="UBitStream.pas"/> 148 <Caret Line=" 165" Column="1" TopLine="142"/>168 <Caret Line="252" Column="1" TopLine="235"/> 149 169 </Position15> 150 170 <Position16> 151 171 <Filename Value="UBitStream.pas"/> 152 <Caret Line=" 161" Column="1" TopLine="142"/>172 <Caret Line="253" Column="1" TopLine="235"/> 153 173 </Position16> 154 174 <Position17> 155 175 <Filename Value="UBitStream.pas"/> 156 <Caret Line=" 162" Column="1" TopLine="142"/>176 <Caret Line="251" Column="1" TopLine="241"/> 157 177 </Position17> 158 178 <Position18> 159 179 <Filename Value="UBitStream.pas"/> 160 <Caret Line=" 163" Column="1" TopLine="142"/>180 <Caret Line="257" Column="1" TopLine="241"/> 161 181 </Position18> 162 182 <Position19> 163 183 <Filename Value="UBitStream.pas"/> 164 <Caret Line=" 165" Column="1" TopLine="142"/>184 <Caret Line="253" Column="45" TopLine="241"/> 165 185 </Position19> 166 186 <Position20> 167 <Filename Value=" UBitStream.pas"/>168 <Caret Line=" 161" Column="1" TopLine="142"/>187 <Filename Value="test.lpr"/> 188 <Caret Line="68" Column="1" TopLine="54"/> 169 189 </Position20> 170 190 <Position21> 171 <Filename Value=" UBitStream.pas"/>172 <Caret Line=" 162" Column="1" TopLine="142"/>191 <Filename Value="test.lpr"/> 192 <Caret Line="70" Column="1" TopLine="54"/> 173 193 </Position21> 174 194 <Position22> 175 <Filename Value=" UBitStream.pas"/>176 <Caret Line=" 163" Column="1" TopLine="142"/>195 <Filename Value="test.lpr"/> 196 <Caret Line="71" Column="1" TopLine="54"/> 177 197 </Position22> 178 198 <Position23> 179 <Filename Value=" UBitStream.pas"/>180 <Caret Line=" 165" Column="1" TopLine="142"/>199 <Filename Value="test.lpr"/> 200 <Caret Line="69" Column="1" TopLine="54"/> 181 201 </Position23> 182 202 <Position24> 183 <Filename Value=" UBitStream.pas"/>184 <Caret Line=" 161" Column="1" TopLine="142"/>203 <Filename Value="test.lpr"/> 204 <Caret Line="73" Column="1" TopLine="54"/> 185 205 </Position24> 186 206 <Position25> 187 <Filename Value=" UBitStream.pas"/>188 <Caret Line=" 162" Column="1" TopLine="142"/>207 <Filename Value="test.lpr"/> 208 <Caret Line="69" Column="1" TopLine="54"/> 189 209 </Position25> 190 210 <Position26> 191 <Filename Value=" UBitStream.pas"/>192 <Caret Line=" 163" Column="1" TopLine="142"/>211 <Filename Value="test.lpr"/> 212 <Caret Line="70" Column="1" TopLine="54"/> 193 213 </Position26> 194 214 <Position27> 195 <Filename Value=" UBitStream.pas"/>196 <Caret Line=" 165" Column="1" TopLine="142"/>215 <Filename Value="test.lpr"/> 216 <Caret Line="72" Column="1" TopLine="54"/> 197 217 </Position27> 198 218 <Position28> 199 <Filename Value=" UBitStream.pas"/>200 <Caret Line=" 161" Column="1" TopLine="142"/>219 <Filename Value="test.lpr"/> 220 <Caret Line="71" Column="1" TopLine="54"/> 201 221 </Position28> 202 222 <Position29> 203 <Filename Value=" UBitStream.pas"/>204 <Caret Line=" 166" Column="62" TopLine="142"/>223 <Filename Value="test.lpr"/> 224 <Caret Line="72" Column="1" TopLine="54"/> 205 225 </Position29> 206 226 <Position30> 207 227 <Filename Value="test.lpr"/> 208 <Caret Line=" 56" Column="26" TopLine="42"/>228 <Caret Line="73" Column="1" TopLine="54"/> 209 229 </Position30> 210 230 </JumpHistory> -
BitStream/test.lpr
r30 r31 16 16 17 17 TTest = class(TCustomApplication) 18 private 19 procedure PrintBitStream(Stream:TBitStream); 18 20 protected 19 21 procedure DoRun; override; … … 39 41 Buffer[2] := $56; 40 42 Buffer[3] := $78; 43 WriteLn('Source data:'); 41 44 PrintData(Buffer); 42 45 43 BitStream.Write(Buffer[0], 27); 46 BitStream.Write(Buffer[0], 28); 47 WriteLn('Write data to stream:'); 48 PrintBitStream(BitStream); 44 49 // Write second bit array after first which lead to store data as shifted 45 BitStream.Write(Buffer[0], 27); 46 47 BitStream.Stream.Position := 0; 48 PrintStream(BitStream.Stream); 50 BitStream.Write(Buffer[0], 28); 51 WriteLn('Append shifted data to stream:'); 52 PrintBitStream(BitStream); 49 53 50 54 // Read test of sub bit array 51 BitStream.Position := 5; 52 BitStream.Read(Buffer[0], 18); 55 BitStream.Position := 1; 56 BitStream.Read(Buffer[0], 32); 57 WriteLn('Read bit data part:'); 53 58 PrintData(Buffer); 54 59 55 60 // Test stream copy 56 BitStream.Position := 2; 57 BitStream2.CopyFrom(BitStream, BitStream.Size); 58 PrintStream(BitStream2.Stream); 61 WriteLn('Copy bit block to another stream:'); 62 for I := 0 to BitStream.Size do begin 63 BitStream.Position := I; 64 BitStream2.Size := 0; 65 BitStream2.CopyFrom(BitStream, BitStream.Size); 66 PrintBitStream(BitStream2); 67 end; 68 for I := 0 to BitStream.Size do begin 69 BitStream.Position := 0; 70 BitStream2.Size := 0; 71 BitStream2.Position := I; 72 BitStream2.CopyFrom(BitStream, BitStream.Size); 73 PrintBitStream(BitStream2); 74 end; 59 75 60 76 BitStream.Destroy; … … 68 84 var 69 85 I: Integer; 86 B: Integer; 87 OneByte: Byte; 70 88 begin 71 for I := 0 to High(Data) do 72 Write(IntToHex(Data[I], 2) + ' '); 89 for I := 0 to High(Data) do begin 90 OneByte := Data[I]; 91 for B := 0 to 7 do 92 Write(IntToStr((OneByte shr B) and 1)); 93 end; 73 94 WriteLn; 74 95 end; … … 77 98 var 78 99 I: Integer; 100 B: Integer; 101 Data: Byte; 102 begin 103 Stream.Position := 0; 104 for I := 0 to Stream.Size - 1 do begin 105 Data := Stream.ReadByte; 106 for B := 0 to 7 do 107 Write(IntToStr((Data shr B) and 1)); 108 end; 109 WriteLn; 110 end; 111 112 procedure TTest.PrintBitStream(Stream: TBitStream); 113 var 114 I: Integer; 79 115 begin 80 116 Stream.Position := 0; 81 117 for I := 0 to Stream.Size - 1 do 82 Write(IntTo Hex(Stream.ReadByte, 2) + ' ');118 Write(IntToStr(Integer(Stream.ReadBit))); 83 119 WriteLn; 84 120 end; -
Comm/UCommSerialPort.pas
r26 r31 45 45 destructor TCommSerialPort.Destroy; 46 46 begin 47 FreeAndNil(DataPin); 47 OnReceiveData := nil; 48 DataPin.Destroy; 48 49 inherited; 49 50 end; -
Comm/USerialPort.pas
r26 r31 77 77 constructor Create; 78 78 destructor Destroy; override; 79 procedure Assign(Source: TObject); 79 80 end; 80 81 … … 175 176 FReceiveThread.Destroy; 176 177 inherited Destroy; 178 end; 179 180 procedure TSerialPort.Assign(Source:TObject); 181 begin 182 if Source is TSerialPort then begin 183 Name := TSerialPort(Source).Name; 184 BaudRate := TSerialPort(Source).BaudRate; 185 Parity := TSerialPort(Source).Parity; 186 StopBits := TSerialPort(Source).StopBits; 187 DataBits := TSerialPort(Source).DataBits; 188 FlowControl := TSerialPort(Source).FlowControl; 189 DTR := TSerialPort(Source).DTR; 190 RTS := TSerialPort(Source).RTS; 191 end else raise Exception.Create('Assignment error'); 177 192 end; 178 193 -
Common/UCommon.pas
r26 r31 4 4 5 5 uses 6 Windows, SysUtils, ShFolder ;6 Windows, SysUtils, ShFolder, ShellAPI; 7 7 8 8 type 9 9 TArrayOfByte = array of Byte; 10 10 TArrayOfString = array of string; 11 11 12 function DelTree(DirName : string): Boolean; 12 13 function IntToBin(Data: Cardinal; Count: Byte): string; 13 14 function TryHexToInt(Data: string; var Value: Integer): Boolean; … … 18 19 function GetUserName: string; 19 20 function SplitString(var Text: string; Count: Word): string; 21 function GetBit(Variable: QWord; Index: Byte): Boolean; 22 procedure SetBit(var Variable: QWord; Index: Byte; State: Boolean); 23 procedure SetBit(var Variable: Cardinal; Index: Byte; State: Boolean); 24 procedure SetBit(var Variable: Word; Index: Byte; State: Boolean); 25 function AddLeadingZeroes(const aNumber, Length : integer) : string; 20 26 21 27 implementation 28 29 function DelTree(DirName : string): Boolean; 30 var 31 SHFileOpStruct : TSHFileOpStruct; 32 DirBuf : array [0..255] of char; 33 begin 34 DirName := UTF8Decode(DirName); 35 try 36 Fillchar(SHFileOpStruct,Sizeof(SHFileOpStruct),0) ; 37 FillChar(DirBuf, Sizeof(DirBuf), 0 ) ; 38 StrPCopy(DirBuf, DirName) ; 39 with SHFileOpStruct do begin 40 Wnd := 0; 41 pFrom := @DirBuf; 42 wFunc := FO_DELETE; 43 fFlags := FOF_ALLOWUNDO; 44 fFlags := fFlags or FOF_NOCONFIRMATION; 45 fFlags := fFlags or FOF_SILENT; 46 end; 47 Result := (SHFileOperation(SHFileOpStruct) = 0) ; 48 except 49 Result := False; 50 end; 51 end; 22 52 23 53 function BCDToInt(Value: Byte): Byte; … … 32 62 Path: array[0..MAX_PATH] of Char; 33 63 begin 64 Result := 'C:\Test'; 34 65 if SUCCEEDED(SHGetFolderPath(0, Folder, 0, SHGFP_TYPE_CURRENT, @path[0])) then 35 66 Result := path … … 133 164 end; 134 165 166 function GetBit(Variable:QWord;Index:Byte):Boolean; 167 begin 168 Result := ((Variable shr Index) and 1) = 1; 169 end; 170 171 procedure SetBit(var Variable:QWord;Index:Byte;State:Boolean); overload; 172 begin 173 Variable := (Variable and ((1 shl Index) xor QWord($ffffffffffffffff))) or (QWord(State) shl Index); 174 end; 175 176 procedure SetBit(var Variable:Cardinal;Index:Byte;State:Boolean); overload; 177 begin 178 Variable := (Variable and ((1 shl Index) xor Cardinal($ffffffff))) or (Cardinal(State) shl Index); 179 end; 180 181 procedure SetBit(var Variable:Word;Index:Byte;State:Boolean); overload; 182 begin 183 Variable := (Variable and ((1 shl Index) xor Word($ffff))) or (Word(State) shl Index); 184 end; 185 186 function AddLeadingZeroes(const aNumber, Length : integer) : string; 187 begin 188 Result := SysUtils.Format('%.*d', [Length, aNumber]) ; 189 end; 190 135 191 end. -
FindFile/UFindFile.pas
r26 r31 27 27 28 28 type 29 EDirNotFound = class(Exception); 30 29 31 TFileAttrKind = (ffaReadOnly, ffaHidden, ffaSysFile, ffaVolumeID, ffaDirectory, ffaArchive, ffaAnyFile); 30 32 TFileAttr = set of TFileAttrKind; … … 83 85 if Value <> '' then 84 86 if DirectoryExists(UTF8Decode(Value)) then 85 fPath := IncludeTrailingBackslash(Value); 87 fPath := IncludeTrailingBackslash(Value) 88 else raise EDirNotFound.Create('Adresář nenalezen'); 86 89 end; 87 90 end; -
MemoryStreamEx/UMemoryStreamEx.pas
r26 r31 85 85 if Position >= Size then Break; 86 86 Data := Chr(ReadByte); 87 if Data <> Terminator[I] then Result := Result + Data 88 else Inc(I); 87 if Data <> Terminator[I] then begin 88 Result := Result + Data; 89 I := 1; 90 end else Inc(I); 89 91 until I > Length(Terminator); 90 92 if not (I > Length(Terminator)) then begin -
PersistentForm/UPersistentForm.pas
r29 r31 30 30 var 31 31 RestoredLeft, RestoredTop, RestoredWidth, RestoredHeight: Integer; 32 RestoredWindowState: TWindowState; 32 33 begin 33 34 with TRegistryEx.Create do … … 48 49 if Form.Top > (Screen.Height - 50) then 49 50 Form.Top := Screen.Height - 50; 50 Form.WindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(wsNormal)));51 if Form.WindowState = wsMaximized then begin51 RestoredWindowState := TWindowState(ReadIntegerWithDefault('WindowState', Integer(wsNormal))); 52 if RestoredWindowState = wsMaximized then begin 52 53 RestoredWidth := ReadIntegerWithDefault('RestoredWidth', Form.RestoredWidth); 53 54 RestoredHeight := ReadIntegerWithDefault ('RestoredHeight', Form.RestoredHeight); … … 56 57 Form.SetRestoredBounds(RestoredLeft, RestoredTop, RestoredWidth, RestoredHeight); 57 58 end; 59 Form.WindowState := RestoredWindowState; 58 60 59 61 if ReadBoolWithDefault('Visible', False) then Form.Show; -
PrefixMultiplier/UPrefixMultiplier.pas
r27 r31 1 1 unit UPrefixMultiplier; 2 3 // Date: 2010-06-01 2 4 3 5 {$mode delphi} -
VarIntSerializer/UVarIntSerializer.pas
r26 r31 11 11 12 12 uses 13 Classes, DateUtils, UMemoryStreamEx, Math, Dialogs, SysUtils ;13 Classes, DateUtils, UMemoryStreamEx, Math, Dialogs, SysUtils, USubStream; 14 14 15 15 const … … 42 42 43 43 // Misc methods 44 function TestMask(Mask , BitIndex: Integer): Boolean;44 function TestMask(Mask: QWord; BitIndex: Byte): Boolean; 45 45 procedure ReadItemByMaskIndex(Index: Integer; Data: TVarIntSerializer); 46 procedure ReadItemRefByMaskIndex(Index: Integer; Data: TSubStream); 46 47 procedure BlockEnclose; 47 48 procedure BlockUnclose; … … 310 311 end; 311 312 312 function TVarIntSerializer.TestMask(Mask , BitIndex: Integer): Boolean;313 function TVarIntSerializer.TestMask(Mask: QWord; BitIndex: Byte): Boolean; 313 314 begin 314 315 Result := ((Mask shr BitIndex) and 1) = 1; … … 322 323 begin 323 324 Position := 0; 325 Data.Size := 0; 324 326 Mask := ReadVarUInt; 325 327 I := 0; … … 330 332 if TestMask(Mask, Index) then 331 333 ReadStream(TStream(Data), GetVarSize); 334 Data.Position := 0; 335 end; 336 337 procedure TVarIntSerializer.ReadItemRefByMaskIndex(Index:Integer;Data:TSubStream 338 ); 339 var 340 Mask: Integer; 341 I: Integer; 342 begin 343 Position := 0; 344 Data.Size := 0; 345 Mask := ReadVarUInt; 346 I := 0; 347 while (Position < Size) and (I < Index) do begin 348 if TestMask(Mask, I) then Position := Position + GetVarSize; 349 Inc(I); 350 end; 351 if TestMask(Mask, Index) then begin 352 if TStream(Self) is TSubStream then begin 353 // Recalculate substream 354 Data.Source := TSubStream(Self).Source; 355 Data.SourcePosition := TSubStream(Self).SourcePosition + Position; 356 end else begin 357 Data.Source := Self; 358 Data.SourcePosition := Position; 359 end; 360 Data.Size := GetVarSize; 361 end; 362 Data.Position := 0; 332 363 end; 333 364 -
VectorObject/UVectorObject.pas
r26 r31 6 6 7 7 uses 8 Classes, SysUtils, Graphics ;8 Classes, SysUtils, Graphics, Contnrs; 9 9 10 10 type … … 36 36 37 37 TVectorLine = class(TVectorObject) 38 Points: T List; // of TVectorDot38 Points: TObjectList; // of TVectorDot 39 39 procedure Add(Position: TPoint); 40 40 procedure Draw; override; … … 80 80 public 81 81 Brush: TBrush; 82 Objects: T List; // of TVectorObject82 Objects: TObjectList; // of TVectorObject 83 83 BitmapCanvas: TCanvas; 84 84 Pen: TPen; … … 136 136 NewPoint := TVectorDot.Create; 137 137 NewPoint.Position := Position; 138 Points.Add(NewPoint); 138 139 end; 139 140 … … 155 156 begin 156 157 inherited; 157 Points := T List.Create;158 Points := TObjectList.Create; 158 159 end; 159 160 160 161 destructor TVectorLine.Destroy; 161 var 162 I: Integer; 163 begin 164 for I := 0 to Points.Count - 1 do 165 TVectorObject(Points[I]).Destroy; 162 begin 166 163 Points.Destroy; 167 164 inherited Destroy; … … 210 207 begin 211 208 inherited; 212 Objects := T List.Create;209 Objects := TObjectList.Create; 213 210 Brush := TBrush.Create; 214 211 Pen := TPen.Create; … … 223 220 Pen.Destroy; 224 221 Brush.Destroy; 225 for I := 0 to Objects.Count - 1 do226 TVectorObject(Objects[I]).Destroy;227 222 Objects.Destroy; 228 223 inherited Destroy;
Note:
See TracChangeset
for help on using the changeset viewer.