[fpc-pascal] Syntax to select constant or variable with function call
James Richters
james at productionautomation.net
Mon Sep 25 19:25:32 CEST 2017
> See what I wrote yesterday :)
Sorry I had a duplicate message, I was having difficulty with my email and accidentally sent a mail with an alias, I thought it was rejected but it was just delayed.
Here is what I have now, and it's working great, thanks for the help.
Function Find_Color(ColorArray : Array of VGARGBRec; R ,G ,B : Word) : Byte;
Var
Dist,Closest:Double;
i,BestChoice:Byte;
Begin
Closest:=200000;
For i:= Low(ColorArray) to High(ColorArray) do
Begin
Dist := ((R-ColorArray[i].R)*(R-ColorArray[i].R))
+ ((G-ColorArray[i].G)*(G-ColorArray[i].G))
+ ((B-ColorArray[i].B)*(B-ColorArray[i].B));
If Dist <= Closest Then
Begin
Closest:=Dist;
BestChoice:=i;
End;
End;
Find_Color:=BestChoice;
end;
Call with:
Find_Color(Arrayname, Red, Green, Blue);
> The loop can still be optimized, but that is another topic.
Please elaborate, I would be very interested in how this could be optimized.
James
More information about the fpc-pascal
mailing list