Re:Re: Delphi Array and MS/Access


[ Delphi Tutorials -- by DelphiLand ]

Posted by Lionel on March 17, 2004 at 13:20:48:

In Reply to: Re: Using a Delphi Array and MS/Access DB to store and retrieve data posted by lionel on March 17, 2004 at 03:51:18:

: : Questions:

: : Before constructing the loop, we must know:

: : - Is there a fixed number of "LegPairs"? If not, we can't use a static array to store the results, but we must use a structure with a dynamic size, such as: a dynamic array, a database on disk, a textfile, or a file-of-records. Of course, then also the structure of the loop changes, like this:

: : while not ItsDone do begin
: : // Calculate records and store: ...
: : end;

: : "ItsDone" can be a function that returns True or False. E.g. return False if no more data available, or if the user clicked a "Stop" button, whatever...

: : - How are the parameters Dist1, Dist2, Angle1, Angle2 obtained?
: : Are they entered in edit-boxes by the user, who clicks a button after each set of data?
: : Or are they obtained from a table on disk, or from a textfile on disk, or from one or more arrays in memory that were filled by some other part of the program?
: : Or are they calculated on the fly, whereby the next set of data is the previous set plus a given increment? Such as: Angle1 varies from 0 to a full circle in 10 increments, the same for Angle2, what would give us 100 sets of coordinates if Dist1 and Dist2 are fixed (10000 sets if D1 and D2 also vary in ten steps each)?

: : So if you give some more details, we could try to complete the code.

: I have not had a chance to review what you sent me but will review it tomorrow and get back in touch.
: ****************************************

I tried to send you the project zipped up but my ISP blocked it. So I will send the following code to show where I am so far.

//-----------Calculate Decimal Degrees and Radians-----
   
procedure TForm1.Button1Click(Sender: TObject);
Var InPutStr, DegStr, MinStr, SecStr: String; PointA, PointB: Variant; PosSpace1, PosSpace2: Integer; Prefix, Suffix: Variant; Lat, Dep, Dist, N1, N2, E1, E2, X, Deg, Min, Sec, DecDeg, Rad: Variant; //------------------------------------------------- Begin //Start the Coordinates procedure //------------------------------------------------- // Input Initial (From Point) number // PointA:=(Edit1.Text); // Initial Coordinates N1:=Edit2.Text; E1:=Edit3.Text; // Input Prefix and Suffix Prefix:=Edit4.Text; Suffix:=Edit6.Text; // Input Distance Dist:=Edit7.Text; // Input second (To point) number PointB:=Edit8.Text; InPutStr:=Trim(Edit5.Text);//Remove unwanted blanks IF Length(InPutStr) > 0 Then begin //if there are any minutes DegStr:=Copy(InPutStr, 1, PosSpace1 - 1);//extract degrees System.Delete(InPutStr, 1, PosSpace1);//remove first part //------------------------------------ PosSpace2:=Pos(' ',InPutStr);//position of second space //------------------------------------- IF PosSpace2 > 0 Then begin//if there are seconds MinStr:=Copy(InPutStr, 1, PosSpace2 - 1);//extract Minutes System.Delete(InPutStr, 1, PosSpace2);//remove second part SecStr:=InPutStr;//seconds are in the third part end //---------------------------------------- ELSE Begin MinStr:=InPutStr;//all that is left are the minutes SecStr:='0';//there are no seconds end; end //------------------------------------------ ELSE Begin//if there are no minutes DegStr:=InPutStr;//degrees take up entire input string MinStr:='0';//there are no minutes SecStr:='0';//there are no seconds end; //--------------------------------------------------- // End of Angle conversion //-----Now lets do some calculations-------------- //----------------------------------------------- Deg:=StrToFloat(DegStr);//assign the value of DegStr to D Min:=StrToFloat(MinStr);//assign the value of MinStr to M Sec:=StrToFloat(SecStr);//assign the value of SecStr to S // Convert DMS to Decimal Degrees DecDeg:=Deg+(Min/60)+(Sec/3600); // Convert Decimal Degrees to Radians Rad:=DecDeg*(Pi/180); X:=Rad;//assign the value of radians to X // Compute Lat and Dep Lat:=Dist*Cos(X); //Lat takes a plus sign if prefix is N else minus Dep:=Dist*Sin(X); //Dep takes a plus sign if suffix is E else minus // Now Determine what is plus and what is minus using Prefix and Suffix //------------------------------------------------ // Use If Then Else to solve for (N2) and (E2) //----------------------------------- IF Prefix = ('N') THEN begin Prefix:='N'; N2:=N1+Lat; end ELSE begin Prefix:='S'; N2:=N1-Lat; end; IF Suffix = ('E') THEN begin Suffix:='E'; E2:=E1+Dep; end ELSE begin Suffix:='W'; E2:=E1-Dep; end; //--------------------------------------- // The end of the calculations // Now display the results //------------------------------------------- Edit9.Text:=FloatToStr(PointA); Edit10.Text:=FloatToStr(PointB); //------------------------------------------- // Bearing shows up in Edit box 11 Edit11.Text:=' '+prefix+' '+FloatToStr(Deg)+#176+' '+ FloatToStr(Min)+' '' '+' '+ FloatToStrF(Sec,ffFixed,2,1)+' " '+suffix; //----------------------------------------------- // Show Distance again in Edit Box 12 Edit12.Text:=FloatToStrF(Dist,ffFixed,8,8); //---------------------------------------------- // Show new computed X and Y Coordinates in Edit Boxes 13 and 14 Edit13.Text:=FloatToStrF(N2,ffFixed,8,8); Edit14.Text:=FloatToStrF(E2,ffFixed,8,8); //----------------------------------------------
end;

Related Articles and Replies:

Re: Delphi Array and MS/Access DB Lionel 3/17/2004
Re: calculate data, store in database webmaster Guido 3/22/2004
Re: calculate data, store in database Lionel 3/23/2004
Re: resend example webmaster Guido 3/23/2004
Re: Problem Lionel 3/24/2004
Re: Problem webmaster Guido 3/24/2004
Re: Problems solved! Lionel Joyner 3/24/2004


[ DelphiLand: free Delphi source code, tips, tutorials ]