Delphi simulate subtraction of angles expressed in degrees °, minutes ' and seconds "

Asked

Viewed 140 times

1

Delphi, Lazarus

I need help from friends, a code. pas to simulate the subtraction of angles expressed in degrees °, minutes ' and seconds " in Delphi or Lazarus, taking the values of two Tedit and giving the result of the subtraction in a Label.

Example

Subtraction

  179°  59'   60"    TEdit1  
  70°   5'   15"    TEdit2  

 109° 54'  45"   resposta  no  Label1  

1 answer

4

Following solution in Delphi, I highlight that Edit1 and Edit2 expect a valid string, with the format: ggº mm' ss"

procedure TForm1.Button1Click(Sender: TObject);

   function GetValorNumerico(const P_Texto: string; const P_Caracter: Char): Integer;
   begin
      case P_Caracter of
         'º': Result := StrToInt(Trim(Copy(P_Texto, 1, Pos(P_Caracter, P_Texto)-1)));
         '''': Result := StrToInt(Trim(Copy(P_Texto, Pos('º', P_Texto)+2, 2)));
         '"': Result := StrToInt(Trim(Copy(P_Texto, Pos('''', P_Texto)+2, 2)));
      end;
   end;

var
   W_Graus1: integer;
   W_Minutos1: integer;
   W_Segundos1: integer;

   W_Graus2: integer;
   W_Minutos2: integer;
   W_Segundos2: integer;

   W_Graus3: integer;
   W_Minutos3: integer;
   W_Segundos3: integer;
begin
   W_Graus1 := GetValorNumerico(Edit1.Text, 'º');
   W_Minutos1 := GetValorNumerico(Edit1.Text, '''');
   W_Segundos1 := GetValorNumerico(Edit1.Text, '"');

   W_Graus2 := GetValorNumerico(Edit2.Text, 'º');
   W_Minutos2 := GetValorNumerico(Edit2.Text, '''');
   W_Segundos2 := GetValorNumerico(Edit2.Text, '"');

   if W_Segundos1 < W_Segundos2 then
   begin
      Dec(W_Minutos1);
      Inc(W_Segundos1, 60);
   end;

   W_Segundos3 := W_Segundos1 - W_Segundos2;

   if W_Minutos1 < W_Minutos2 then
   begin
      Dec(W_Graus1);
      Inc(W_Minutos1, 60);
   end;

   W_Minutos3 := W_Minutos1 - W_Minutos2;

   W_Graus3 := W_Graus1 - W_Graus2;

   Label1.Caption := Format('%dº %d'' %d"', [W_Graus3, W_Minutos3, W_Segundos3]); 
end;
  • Hi Melissa had computer problem and saw only today (May 1)

  • Hi Melissa my name Alessandro I had computer problem and I saw your post only today (May 1) grateful for the code I will test it. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.