Created
September 26, 2015 22:52
-
-
Save JohnPeel/bbae76f241376c419f93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program new; | |
type | |
PPInt8 = ^PInt8; | |
PInt8 = ^Int8; | |
function __Find(const Arr, Item: Pointer; const ItemSize, ItemCount: SizeInt): Int32; | |
function _CompareMem(const Item1, Item2: PInt8; const ItemSize: SizeInt): Boolean; | |
var | |
I: SizeInt; | |
begin | |
Result := True; | |
for I := 0 to ItemSize - 1 do | |
if (Item1[I]^ <> Item2[I]^) then | |
Exit(False); | |
end; | |
var | |
Ptr: PInt8 := PPInt8(Arr)^; | |
Start: PtrUInt := PtrUInt(Ptr); | |
begin | |
Result := -1; | |
while ((PtrUInt(Ptr) - Start) < (ItemSize * ItemCount)) do | |
begin | |
if (_CompareMem(Ptr, Item, ItemSize)) then | |
Exit((PtrUInt(Ptr) - Start) div ItemSize); | |
Inc(Ptr, ItemSize); | |
end; | |
end; | |
var | |
P: TPoint := Point(6, 3); | |
TPA: array of TPoint := [Point(3, 2), Point(-1, 4), Point(6, 3), Point(4, 2)]; | |
begin | |
ClearDebug; | |
WriteLn(__Find(@TPA, @P, SizeOf(TPoint), Length(TPA))); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment