Thursday, March 29, 2018

DELPHI - How get greatest common divisor (for two digits)

The function returns greatest common divisor for two digits. When it does not found it, returns 1.
function GCD( _iNumber1, _iNumber2 : integer ) : integer;
var
  iTemp : integer;
begin
  if _iNumber1 < 0 then _iNumber1 := -_iNumber1;
  if _iNumber2 < 0 then _iNumber2 := -_iNumber2;

  repeat

    if _iNumber1 < _iNumber2 then
      begin
        iTemp := _iNumber1;
        _iNumber1 := _iNumber2;
        _iNumber2 := iTemp;
      end;

    _iNumber1 := _iNumber1 mod _iNumber2;

  until ( _iNumber1 = 0 );

  result := _iNumber2;
end;
Calling:
var
  i : integer;
begin
  i := GCD( 12, 16 );

  ShowMessage( IntToStr( i ) );
end;
Output:

Wednesday, March 28, 2018

DELPHI - How to show chi-square distribution curve

Propability density function (chi-square distribution).
var
  i, iK : integer;
  iX, iY, iGamma, iNumerator, iDenominator : double;
  pSerie : TLineSeries;
  pIntegral : TIntegral;
begin
  Memo1.Clear;

  pSerie := TLineSeries( Chart1.Series[0] );
  pSerie.Clear;

  pIntegral := TIntegral.Create;
  pIntegral.iStep := 0.05;
  pIntegral.SetInterval( 0.001, 20 );

  { -- set param + calc GAMMA function }

  iK := 8;
  iGamma := GetGamma( iK/2 );

  for i := 0 to pIntegral.pX.Count - 1 do
    begin
      iX := pIntegral.pX.GetValue( i );

      try
        iNumerator := power( iX, iK/2-1 ) * exp( ( -1*iX ) /2 );
        iDenominator := power( 2, iK / 2 ) * iGamma;

        if iDenominator <> 0 then
          iY := iNumerator / iDenominator
        else
          iY := 0;
      except
        iY := 0;
      end;
      pIntegral.pY.AddValue( iY );

      { -- add to chart }

      pSerie.AddXY( iX, iY );
    end;
end;
And here is very important Gamma() function with k parameter.
function GammaStirF( X : double ) : double;
var
  y : double;
  w : double;
  v : double;
  stir : double;
begin
  w := 1 / x;
  stir := 7.87311395793093628397E-4;
  stir := -2.29549961613378126380E-4 + w * stir;
  stir := -2.68132617805781232825E-3 + w * stir;
  stir := 3.47222221605458667310E-3 + w * stir;
  stir := 8.33333333333482257126E-2 + w * stir;
  w := 1 + w * stir;
  y := exp(x);
  if x > 143.01608 then
    begin
      v := power( x, 0.5 * x -0.25 );
      y := v *( v / y );
    end
  else
    begin
      y := power( x, x -0.5 ) / y;
    end;
  result := 2.50662827463100050242 * y * w;
end;

function GetGamma( _x : double ) : double;
var
  p : double;
  PP : double;
  q : double;
  QQ : double;
  z : double;
  i : longint;
  SgnGam : double;
begin
  SgnGam := 1;
  q := abs( _x );
  if q > 33.0 then
  begin
    if _x < 0.0 then
    begin
      p := floor(q);
      i := round(p);

      if i mod 2 = 0 then
      begin
        SgnGam := -1;
      end;

      z := q - p;

      if z > 0.5 then
      begin
        p := p+1;
        z := q-p;
      end;

      z := q * sin( pi * z );
      z := Abs(z);
      z := pi / ( z * GammaStirF( q ) );
    end
    else
    begin
      z := GammaStirF( _x );
    end;
    result := SgnGam * z;
    exit;
  end;
  z := 1;
  while _x >= 3 do
  begin
    _x := _x - 1;
    z := z *_x;
  end;
  while _x < 0 do
  begin
    if _x > -0.000000001 then
    begin
      result := z / ( ( 1 + 0.5772156649015329 *_x ) * _x );
      exit;
    end;
    z := z /_x;
    _x := _x + 1;
  end;
  while _x < 2 do
  begin
    if _x < 0.000000001 then
    begin
      result := z / ( ( 1 + 0.5772156649015329 * _x ) *_x );
      exit;
    end;
    z := z /_x;
    _x := _x + 1.0;
  end;
  if _x = 2 then
  begin
    result := z;
    exit;
  end;

  _x := _x - 2.0;
  PP := 1.60119522476751861407E-4;
  PP := 1.19135147006586384913E-3 + _X * PP;
  PP := 1.04213797561761569935E-2 + _X * PP;
  PP := 4.76367800457137231464E-2 + _X * PP;
  PP := 2.07448227648435975150E-1 + _X * PP;
  PP := 4.94214826801497100753E-1 + _X * PP;
  PP := 9.99999999999999996796E-1 + _X * PP;
  QQ := -2.31581873324120129819E-5;
  QQ := 5.39605580493303397842E-4 + _X * QQ;
  QQ := -4.45641913851797240494E-3 + _X * QQ;
  QQ := 1.18139785222060435552E-2 + _X * QQ;
  QQ := 3.58236398605498653373E-2 + _X * QQ;
  QQ := -2.34591795718243348568E-1 + _X * QQ;
  QQ := 7.14304917030273074085E-2 + _X * QQ;
  QQ := 1.00000000000000000320 + _X * QQ;

  result := z * PP / QQ;
  exit;
end;
Output:
k=2
k=8

Tuesday, March 27, 2018

Thursday, March 22, 2018

DELPHI - How to show normal distribution curve (Gaussian)

Typical propability density function (Gaussian distribution).
var
  i : integer;
  iY : double;
  pDN : TDistribution_Normal;
  pSerie : TLineSeries;
begin
  Memo1.Clear;

  /* prepare chart */

  pSerie := TLineSeries( Chart1.Series[0] );
  pSerie.Clear;

  /* prepare distribution data */

  pDN := TDistribution_Normal.Create;
  pDN.Init( 0, 1 );

  for i := 0 to pDN.pIntegral.pY.Count - 1 do
    begin
      { -- get value }

      iY := pDN.pIntegral.pY.GetValue( i );

      pSerie.AddXY( i, iY );
    end;

And here is very important TDistribution_Normal.Init() function with parameters as MEAN and SIGMA, here is generated range MEAN +-3.5 SIGMA.
The sum values under curve is equeal to 1.
function TDistribution_Normal.Init( _iMean, _iSigma : double ) : boolean;
var
  i : integer;
  iFrom, iTo, iValue : double;
begin
  result := false;

  { -- check }

  if _iSigma <= 0 then
    begin
      ShowMessage( 'Distribution_Normal() - standard deviation can`t be 0.' );
      exit;
    end;

  { -- add range -3.5 sigma - Mean - + 3.5 sigma }

  pIntegral.Clear;

  iFrom := _iMean - ( 3.5 * _iSigma );
  iTo := _iMean + ( 3.5 * _iSigma );
  { aproximation - 300 items }
  pIntegral.iStep := ( iTo - iFrom ) / 300;
  pIntegral.SetInterval( iFrom, iTo );

  { -- calc values normal distribution for every X }

  for i := 0 to pIntegral.pX.Count - 1 do
    begin
      iValue := ( 1 / ( _iSigma * sqrt( 2*pi ) ) ) * 
                exp( - ( sqr( pIntegral.pX.GetValue( i ) - _iMean ) ) / 
                ( 2 * sqr( _iSigma ) ) );

      pIntegral.pY.AddValue( iValue );
    end;

  pIntegral.Calc;

  result := true;
end;
Output:

Wednesday, March 21, 2018

JAVAFX - How fill and work with PieChart (graph)

import javafx.scene.chart.PieChart;
...
@FXML PieChart pieChart1;
...
/* set text */
    
pieChart1.setTitle( "This is a chart" );        

/* add data */
    
ObservableList series = FXCollections.observableArrayList(); 
series.add( new PieChart.Data( "Q1", 5 ) );
series.add( new PieChart.Data( "Q2", 5.5 ) );
series.add( new PieChart.Data( "Q3", 8 ) );
series.add( new PieChart.Data( "Q4", 3 ) );
         
pieChart1.setData( series ); 
Output:

JAVAFX - How fill and work with BarChart (graph)

import javafx.scene.chart.BarChart;
...
@FXML BarChart barChart1;
...
/* set texts */
    
barChart1.setTitle( "This is a chart" );
    
barChart1.getXAxis().setLabel( "x axis" );
barChart1.getYAxis().setLabel( "y axis" );
   
barChart1.setLegendVisible( false );

/* add data */
    
XYChart.Series series1 = new XYChart.Series();    
series1.getData().add( new XYChart.Data( "Q1", 5 ) );
series1.getData().add( new XYChart.Data( "Q2", 5.5 ) );
series1.getData().add( new XYChart.Data( "Q3", 8 ) );
series1.getData().add( new XYChart.Data( "Q4", 3 ) );        
         
barChart1.getData().add( series1 );       
Output:

Tuesday, March 20, 2018

DELPHI - How get hash value for file (SHA-1 fingerprint)

Hash function returns same value for same (in this case) file. This uses SHA-1 (Secure Hash Algorithm) algorithm.
uses IdHashMessageDigest;
...
var
  sFile : string;
  pSHA : TIdHashSHA1;
  pStream : TFileStream;
begin
  sFile := 'c:\_ax\error.png';

  pSHA := TIdHashSHA1.Create;
  pStream := TFileStream.Create( sFile, fmOpenRead or fmShareDenyWrite );

 try
   ShowMessage( 'File fingerprint = ' + pSHA.HashStreamAsHex( pStream ) );
 finally
   pStream.Free;
   pSHA.Free;
 end;
Output:

JAVAFX - How make "raw" object centering in the form (with properties binding)

public class FXMLMainController implements Initializable {
  
  @FXML private Label lbl1;
  
  @Override
  public void initialize( URL url, ResourceBundle rb ) {               
  }  
  
  /* Method for label centering */

  public void prepare() {
    Scene scene = lbl1.getScene();       
  
    if ( scene != null ) {
      lbl1.layoutXProperty().bind( scene.widthProperty().subtract( 
        lbl1.layoutBoundsProperty().get().getWidth()).divide( 2 ) );
      
      lbl1.layoutYProperty().bind( scene.heightProperty().subtract( 
        lbl1.layoutBoundsProperty().get().getHeight()).divide( 2 ) );
    }
    
  }
}
Method prepare() must be called after creating Scene class instance:
@Override
    public void start(Stage stage) throws Exception {

        FXMLLoader fLoader = new FXMLLoader( getClass().getResource( "FXMLMain.fxml" ) );
        Parent root = fLoader.load();
        FXMLMainController controller = fLoader.< fxmlmaincontroller >getController();      
        
        Scene scene = new Scene(root);
        
        stage.setScene(scene);
        stage.show();

        /* needs to be called here */
        controller.prepare();
    }
Output:

Monday, March 19, 2018

DELPHI - How get hash value for string (SHA-1 fingerprint)

Hash function returns same value for same string. This uses SHA-1 (Secure Hash Algorithm) algorithm.
uses IdHashSHA;
...
var
  pSHA : TIdHashSHA1;
begin
  pSHA := TIdHashSHA1.Create;

  try
    ShowMessage( 'abc = ' + pSHA.HashStringAsHex( 'abc' ) + #13 +
                 'abc = ' + pSHA.HashStringAsHex( 'abc' ) + #13 +
                 'abd = ' + pSHA.HashStringAsHex( 'abd' ) );
  finally
    pSHA.Free;
  end;
Output:

Friday, March 16, 2018

DELPHI - How get MD5 hash value for string (RSA-MD5 fingerprint)

Hash function returns same value for same string. This uses RSA-MD5 algorithm.
uses IdHashMessageDigest;
...
var
  pMD5: TIdHashMessageDigest5;
begin
  pMD5 := TIdHashMessageDigest5.Create;
  try
    ShowMessage( 'abc = ' + pMD5.HashStringAsHex( 'abc' ) + #13 +
                 'abc = ' + pMD5.HashStringAsHex( 'abc' ) + #13 +
                 'abd = ' + pMD5.HashStringAsHex( 'abd' ) );
  finally
    pMD5.Free;
  end;
Output:

Thursday, March 15, 2018

AX - How check free space in sequences (=if sequences have space for growing)

Sometimes you need to know, which sequences are full - or near to full.
This SQL script shows free space in sequences in percent.
select a.* 
from
(
select a.*, 
cast( cast( a.[free] as numeric(15,2) ) / cast( a.[space] as numeric(15,2) ) * 100 
as numeric(15,2) ) as [free_%] 
from
(
select a.numbersequence, a.lowest, a.highest, a.nextrec, 

a.highest - a.lowest as [space],
a.highest - a.nextrec as [free]

from numbersequencetable a
where
a.blocked = 0 and
a.cyclic = 0
) a
) a
order by a.[free_%]
Output:
numbersequence lowest      highest     nextrec     space       free        free_%
-------------- ----------- ----------- ----------- ----------- ----------- --------
Inve_38        1           999999      703701      999998      296298      29.63
Inve_33        1           99999       31366       99998       68633       68.63
Gene_24        1           99999       29841       99998       70158       70.16
Time_6         1           9999999     2665830     9999998     7334169     73.34
Docu_3         1           99999       19037       99998       80962       80.96
Prod_26        1           9999999     1327561     9999998     8672438     86.72
Prod_27        14000       999999      130299      985999      869700      88.20

Wednesday, March 14, 2018

WIN OS - How show user accounts dialog

..for example for possibility to change saved passwords.

From command line:
control userpasswords2
Output:

SQL SERVER - How update statistics for all DB tables

use framework;
exec sp_updatestats;
Output:
Updating [dbo].[sql_detail_graphs]
    [PK__sql_deta__3213E83F07EFD247] has been updated...
    [_WA_Sys_00000002_00507F52] has been updated...
    [_WA_Sys_0000000A_00507F52] has been updated...
    [_WA_Sys_00000009_00507F52] has been updated...
    [_WA_Sys_00000003_00507F52] has been updated...
    5 index(es)/statistic(s) have been updated, 0 did not require update.
 
Updating [dbo].[sql_zal]
    0 index(es)/statistic(s) have been updated, 0 did not require update.
...
Statistics for all tables have been updated.

Tuesday, March 13, 2018

SQL SERVER - INSERT trigger

Sometimes you need to perform some actions immediately after you insert row to table. For this purpose you can use insert trigger on the table.
Pseudo-table named "inserted" contains inserted data row - you probably utilize it here.
ALTER trigger [dbo].[sql_insert]
on [dbo].[sql]
for insert
as
  begin transaction;
  
  begin try

    /* -- add new initial role */

    insert into [role_object]
    ( ident, [description], [role_object_type_ident] )
    select inserted.id, null, 'Q' from inserted;  
  
    /* -- add log row about creation to log table */
  
    insert into sql_detail_changes
    ( sql_id, [description], [type] )
    select inserted.id, 'Creation', 'I' from inserted;  
    
    if @@TRANCOUNT > 0 commit transaction;      
  end 

  /* -- problem ? */

  try begin catch
    if @@TRANCOUNT > 0 rollback transaction;      
  end catch;  

Monday, March 12, 2018

JAVA - How to split string to parts (java.util.StringTokenizer)

Another variant for string split - class java.util.StringTokenizer:
StringTokenizer pSpaceDelim = new StringTokenizer( "This is a text." );
           
System.out.println( "Count = " + pSpaceDelim.countTokens() + System.lineSeparator() );
    
while ( pSpaceDelim.hasMoreTokens() )
  System.out.println( pSpaceDelim.nextToken() );
Output:
Count = 4

This
is
a
text.
NOTE: System.lineSeparator() is system dependent line separator.

SQL SERVER - How use COLLATE over special chars

Sometimes (dependent how is your DB created) you need specify character set for some command that used special text chars. Here, for example in WHERE section.
Without COLLATE..
select count( * ) as rows
from salesline a
where
a.itemid = 'PŘEPRAVNÉ' and
a.confirmeddlv >= '2018/02/01' and
a.confirmeddlv <= '2018/02/07'
Output:
rows
-----------
0

(1 row(s) affected)
..you get empty result set.

But with COLLATE..
select count( * ) as rows
from salesline a
where
a.itemid collate latin1_general_ci_ai = 'PŘEPRAVNÉ' and
a.confirmeddlv >= '2018/02/01' and
a.confirmeddlv <= '2018/02/07'
Output:
rows
-----------
4

(1 row(s) affected)
..it is something else.

NOTE: Collate DB parameter you can get from DB properties.

Friday, March 9, 2018

DELPHI - How compute integral - (sin(x))^2 dx from 0 to PI

For integration is used class TIntegral which use for calculation trapezoidal rule.
procedure TForm1.BIntegralClick(Sender: TObject);
var
  i : integer;
  iX, iY : double;
  pIntegral : TIntegral;
  pSerie : TLineSeries;
begin
    pSerie := TLineSeries( Chart1.Series[0] );
    pSerie.Clear;

    { -- prepare integral class - interval 0..PI }

    pIntegral := TIntegral.Create;
    pIntegral.SetInterval( 0, pi );

    for i := 0 to pIntegral.pX.Count - 1 do
      begin
        { calc Y value }
        pIntegral.pY.AddValue( sqr( sin( pIntegral.pX.GetValue( i ) ) ) );

        { -> to graph }
        iX := pIntegral.pX.GetValue( i );
        iY := pIntegral.pY.GetValue( i );
        pSerie.AddXY( iX, iY );
      end;

    ShowMessage( FloatToStr( pIntegral.Calc ) );        // 1.57

    pIntegral.Free;
end;
Here is TIntegral.calc() method:
{ ---------------------------------------------------------------------------
  Method computes integral value (trapezoidal rule).  
  -------------------------------------------------------------------------- }
function TIntegral.Calc( _iCheckSumIntegralValue : double = 999 ) : double;
var
  i, iDeleteXFrom : integer;
  iValue : double;
begin
  result := 0;

  { -- checks }

  if pX.Count < 2 then exit;
  if pX.Count <> pY.Count then exit;

  { -- delete values }

  pIntegral.Clear;
  pCumulation.Clear;

  { -- trapezoidal rule }

  iDeleteXFrom := -1;

  for i := 1 to pX.Count - 1 do
    begin
      { -- compute integral value in interval }

      iValue := (
                  ( pX.GetValueCheckNull( i ) - pX.GetValueCheckNull( i - 1 ) )
                  *
                  ( ( pY.GetValueCheckNull( i ) + pY.GetValueCheckNull( i - 1 ) ) / 2 )
                );

       result := result + iValue;

       { -- check -> is greater than parameter ? }

       if _iCheckSumIntegralValue <> 999 then
       if result > _iCheckSumIntegralValue then
         begin
           { -- subtract }
           result := result - iValue;

           { -- index for removing }
           iDeleteXFrom := i;

           break;
         end;

       { -- record values }

       if bLogIntegral then pIntegral.AddValue( iValue );
       if bLogCumulation then pCumulation.AddValue( result );
     end;

  { -- delete items over test value (if exists) }

  if iDeleteXFrom <> -1 then
    for i := pX.Count - 1 downto iDeleteXFrom do
      begin
        pX.Delete( i );
        pY.Delete( i );
      end;

end;
Output:














And check (same result):

JAVA - How convert decimal to binary, hex, octal etc.

For converting from decimal to binary, hexadecimal, octal etc., use function Integer.toString().
Second parameter is base.
String sText = "";
Integer iValue;
String sValue = "";

/* -- convert from dec */

sValue = Integer.toString( 100, 10 );
sText += "dec(100) to dec =" + sValue + "\n";

sValue = Integer.toString( 100, 2 );
sText += "dec(100) to bin =" + sValue + "\n";

sValue = Integer.toString( 100, 16 );
sText += "dec(100) to hex =" + sValue + "\n";

sValue = Integer.toString( 255, 16 );
sText += "dec(255) to hex =" + sValue + "\n";

/* result */

memo.setText( sText );      
Output:

JAVA - How convert binary, hex, octal etc. to decimal

For converting from binary, hexadecimal, octal etc. to decimal, use function Integer.parseInt(). Second parameter is base.
String sText = "";
Integer iValue;
String sValue = "";
    
/* -- convert to dec */
    
iValue = Integer.parseInt( "100", 10 );    
sText += "dec(100) to dec = " + iValue.toString() + "\n";
    
iValue = Integer.parseInt( "100", 2 );    
sText += "bin(100) to dec = " + iValue.toString() + "\n";

iValue = Integer.parseInt( "100", 16 );    
sText += "hex(100) to dec = " + iValue.toString() + "\n";

iValue = Integer.parseInt( "ff", 16 );    
sText += "hex(ff) to dec = " + iValue.toString() + "\n";

/* result */
    
memo.setText( sText );      
Output:

Thursday, March 8, 2018

DELPHI - How get angle between points

This function:
{ ---------------------------------------------------------------------------
  Function calculate angle between points _iSource and _iDest in direction
  from _iSource.

  Returns value [0-360]. 
  -------------------------------------------------------------------------- }
function CalcAngle( _iSource, _iDest : TPoint ) : double;
var
  iAngle : extended;
begin
  iAngle := ArcTan2( _iSource.Y - _iDest.Y, _iSource.X - _iDest.X );

  result := ( iAngle * 180 ) / pi;

  { greater than 180 is negative -> change it }
  if result < 0 then
    result := 180 + ( 180 + result );
end;
And here is calling examle:
procedure TForm1.Button2Click(Sender: TObject);
var
  pt1, pt2, pt3, pt4 : TPoint;
  iResult1, iResult2, iResult3 : double;
begin
  pt1.x := 50; pt1.y := 50;
  pt2.x := 100; pt2.y := 100;
  pt3.x := 150; pt3.y := 50;
  pt4.x := 100; pt4.y := 150;

  iResult1 := CalcAngle( pt2, pt1 );
  iResult2 := CalcAngle( pt2, pt3 );
  iResult3 := CalcAngle( pt2, pt4 );

  ShowMessage( iResult1.ToString() + ' , ' + iResult2.ToString() + ' , ' + iResult3.ToString );
end;
Output:

DELPHI - How to call (old) BDE stored procedure

Note: orcl is TDatabase with connection.
var
  pStoredProc : TStoredProc;
begin
  try

    pStoredProc := TStoredProc.Create( Application );
    pStoredProc.DatabaseName := orcl.DataBaseName;

    { -- call stored procedure }

    pStoredProc.StoredProcName := AnsiUpperCase(  'factory.an_p1.Sql_Standard_DeleteDay' );
    pStoredProc.Prepare;
    pStoredProc.Params.ParamByName( 'pPeriod' ).AsString := _sPeriod;
    pStoredProc.ExecProc;

  finally
    pStoredProc.Free;
  end;

Wednesday, March 7, 2018

DELPHI - How add item (with more columns) to TListView

var
  pItem : TListItem;
begin
  ...
  Item := List.Items.Add;
  pItem.ImageIndex := -1;
  pItem.Caption    := IntToStr( iCounter );
  pItem.SubItems.Add( s.Name );
  pItem.SubItems.Add( IntToStr( iRowCount ) );
  pItem.SubItems.Add( IntToStr( iRowCountSum ) );
Output:

Friday, March 2, 2018

DELPHI - How get row count in text file

var
  iRowCount : integer;
  F : TextFile;
begin
  ...
  { read row count }
  try
    iRowCount := 0;

    AssignFile( F, EPath.Text + s.Name );
    Reset( F );
    while not EOF( F ) do
      begin
        readln( F, sText );
        inc( iRowCount );
      end;   
     ...       
   finally
     CloseFile( F );
   end;
...

DELPHI - How to make cubic B-Spline interpolation + Cox-De-Boora algorithmus

const giCount = 15;
      giDetail = 10;
...
procedure TForm1.BSpline_Clamped;
var
  j, i, iIndex : integer;
  iNumSegmentsCount : integer;
  iT, i1_T, iB0, iB1, iB2, iB3 : double;
  iNewX, iNewY : double;
  pSerieLine : TLineSeries;
  iValue : extended;
begin

  pSerieLine := TLineSeries( Chart1.Series[1] );
  pSerieLine.Clear;

  { draw count of cubic curves }
  for iIndex := -2 to px.Count - 2 do
    begin

       { every curve generate from I parts }
       for i := 0 to giDetail - 1 do
         begin
           iT := i / (giDetail-1);
           i1_T := 1 - iT;

           iB0 := ( i1_T * i1_T * i1_T ) / 6;
           iB1 := ( ( 3 * iT * iT * iT ) - ( 6 * iT * iT ) + 4 ) / 6;
           iB2 := ( ( -3 * iT * iT * iT ) + ( 3 * iT * iT ) + ( 3 * iT ) + 1 ) / 6;
           iB3 := ( iT * iT * iT ) / 6;

           iNewX := iB0 * GetValueX( iIndex ) +
                    iB1 * GetValueX( iIndex + 1 ) +
                    iB2 * GetValueX( iIndex + 2 ) +
                    iB3 * GetValueX( iIndex + 3 )
                    ;

           iNewY := iB0 * GetValueY( iIndex ) +
                    iB1 * GetValueY( iIndex + 1 ) +
                    iB2 * GetValueY( iIndex + 2 ) +
                    iB3 * GetValueY( iIndex + 3 );

           pSerieLine.AddXY( iNewX, iNewY );
         end;
  end;
  
end;

JAVA - How check if client is reachable - ping to client

String sText = "";
try {

  /* prepare IP address */
      
  String ipAddress = "10.26.1.3";
  InetAddress inet = InetAddress.getByName( ipAddress );

  /* check ping (timeout=1000 ms) */

  if ( inet.isReachable( 1000 ) ) 
    sText = "Client is reachable";
  else
    sText = "Client isn`t reachable";     
      
} catch( UnknownHostException ex ) {
  Logger.getLogger( FXMLMainController.class.getName() ).log( Level.SEVERE, null, ex );
} catch( IOException ex ) {
  Logger.getLogger( FXMLMainController.class.getName() ).log( Level.SEVERE, null, ex );
}
    
memo.setText( sText );    

SQL SERVER - How list active sessions

For listing active server sessions use this stored procedure:
exec sp_who
Or newest:
exec sp_who2
Output:
SPID  Status     Login       HostName       BlkBy DBName    Command          CPUTime DiskIO LastBatch      SPID  REQUESTID
----- ---------- ----------- ------------- ----- --------- ---------------- ------- ------ -------------- ------ ---------
...
65    sleeping   dd\tommy    PWSQ777         .   framework AWAITING COMMAND 0       20     02/14 10:55:32 65    0    
66    sleeping   ron         HP4004888       .   framework AWAITING COMMAND 204     7      03/02 08:02:14 66    0    
67    sleeping   flash       HP3010999       .   framework AWAITING COMMAND 95      0      03/02 07:12:17 67    0