Wolfgan 17 Junior Poster

What is the difficulty. You have already prompted all that is required. Think beyond yourself. This is an elementary task.

Wolfgan 17 Junior Poster

I do not understand why you need random numbers. 12,13,14 - this sequence.

Wolfgan 17 Junior Poster
uses
  Math;
....
var
  d: integer;
begin
  d :=  RandomRange(10,100);
end;
Wolfgan 17 Junior Poster

Try this. I have not tested the speed. Just as an option.

procedure TForm1.Button1Click(Sender: TObject);
var List: TStringList;
begin
  List:=TStringList.Create;
    try
      List.Assign(ListBox1.Items);
      List.CustomSort(TStringsSort);
      ListBox1.Items.Assign(List);
    finally
      List.Free;
    end;
end;
function TStringsSort(List: TStringList; Index1, Index2: Integer): Integer;
begin
  Result:=-CompareStr(List[Index1],List[Index2]);
end
Wolfgan 17 Junior Poster

Just Draw in the OnPaint event and everything will be okay. Or call the drawing functions from this event.

In this matter, I gave an example (attached file):
http://www.daniweb.com/software-development/pascal-and-delphi/threads/356130

Wolfgan 17 Junior Poster

Project -> Options -> Application -> Enable Runtime Themes - uncheck this

Wolfgan 17 Junior Poster

Write a task that is necessary. The code is not completely understood.
As I understand it there are 2 of the array. Need to multiply their elements and get summ? If yes, then this:

sum := 0;
  for i:=1 to 80 do
   begin
     naspole1[i]:=pole1[i]*pole2[i];
     sum := sum + naspole1[i];
     writeln(naspole1[i]);
   end;
   writeln(sum);
Wolfgan 17 Junior Poster

In your case this is not visible. I do not understand what exactly you need. Write more, or give a full job.

Wolfgan 17 Junior Poster
nas := 0; 
for i:=1 to 80 do 
 begin
   naspole1[i]:=pole1[i]*pole2[i]+nas;
   if naspole1[i] >= 10 then
     begin
       naspole1[i] := naspole1[i] div 10;
       nas := naspole1[i] mod 10;
     end;
   write(naspole1[i]);
 end;
Wolfgan 17 Junior Poster

Almost all that is written for Delphi important for Lazarus. Because search for information for dolphins if you can not find Lazarus.
I'm trying to say that you are using an array in vain for the TImage. If you lozhish component on the form, the form is aware of this component. Accordingly, we can use it (see property Components [] and Controls []). These properties are available for all window components. The only thing you have used two-dimensional array, and these properties - a linear list. This is not a problem, you can always calculate the row and column in a linear array, knowing the width and height of the matrix.
In addition, instead of the array is much more convenient to use the class TObjectList.

There is no time, but later I'll show an example of how you can use these properties to emulate the array. I think many students at this site will be useful. I myself have not a student.

Wolfgan 17 Junior Poster

Learn to read the documentation. The note says it all. I already wrote that you invented the wheel in an array. Now you again that it invents. It's time to read and not poke your finger into the sky.

way 1

procedure TSecondForm.Button1Click(Sender: TObject);
var
  bmp: TBitmap;
  idx: Integer;
begin
   bmp := TBitmap.Create;
   try
     for idx := 0 to ImageList.Count - 1 do
      begin
         ImageList.GetBitmap(idx,bmp);
         Canvas.Draw(0,idx*bmp.Height,bmp);
      end;
   finally
     bmp.Free;
   end;
end;

way 2

procedure TSecondForm.Button2Click(Sender: TObject);
var
  idx: Integer;
begin
  for idx := 0 to imageList.Count - 1 do
    ImageList.Draw(Canvas,0,idx*ImageList.Height,idx);
end;

I would have done something like this code:

procedure TSecondForm.Button3Click(Sender: TObject);
var
  bmp: TBitmap;
  idx,i: Integer;
begin
   bmp := TBitmap.Create;
   try
      i := 0;
      for idx := 0 to ComponentCount-1 do
       if (Components[idx] is TImage) then
       begin
          ImageList.GetBitmap(i,bmp);
          (Components[idx] as TImage).Picture.Assign(bmp);
          Inc(i);
       end;
   finally
     bmp.Free;
   end;
end;
Wolfgan 17 Junior Poster
function IntToBin( Value: integer; Digits: integer ): string;
begin
  result := StringOfChar ( '0', digits ) ;
    while value > 0 do begin
      if (value and 1) = 1 then
        result[digits] := '1';
      dec (digits) ;
      value := value shr 1;
    end;
end;
november_pooh commented: Thx.. :) +3
Wolfgan 17 Junior Poster

It's very simple. Use components Indy (TIdHttp) http://www.delphigroups.info/2/5/487672.html

or http://www.realthinclient.com/ (TrtcHttpClient)

Wolfgan 17 Junior Poster

Yes, I forgot to say that this method should be used when dynamically creating dialogues. This will save memory, because memory will be allocated and freed as needed. What would it work to remove the line to automatically create a form. This can be done from the menu in two ways:
1. Open Project -> View source and remove Application.CreateForm(TOKRightDlg, OKRightDlg);
2. Open Project -> Options -> Forms and move TOKRightDlg from Auto-create form to Available form

This requires some programming experience. Therefore recommend that you do not do this, let the form is automatically created. Just a little change code:

procedure TNeuralNetworkInterface.Button2Click(Sender: TObject);
begin
  with OKRightDlg do
     if Execute() then
     begin
        NN.createNetwork(OKRightDlg.NrOfInput,OKRightDlg.NrOfOutput,OKRightDlg.useHidden);
     end;
end;

Dynamic creation of forms related to professional programming. This greatly saves memory when the program lots of dialogue. It is also not very good to automatically create dialogues that are rarely used. Eg "About".
This is a good style. But beware! If you forget to free memory, then get a leak! Program during the work will always spend more and more memory. Windows did not like, the computer begins to slow down.

You can do this:

OKRightDlg := TOKRightDlg.Create(self);
OKRightDlg.DoSometing();
OKRightDlg.Free;

However, it is dangerous. If the method DoSometing an exception is thrown, then the method is not called Free and you get a memory leak.
Use this:

OKRightDlg := TOKRightDlg.Create(self);
try
 OKRightDlg.DoSometing();
finally
 OKRightDlg.Free;
end;
Wolfgan 17 Junior Poster

Very simple. In the main form, you give a link to the second module. In the main module creates an event handler by pressing a button and write code like this (in the second module does not need links to the main module):

unit MainForm;

..........


uses
  SecondForm;

TMainForm.Button1Clicck(Sender: TObject);
begin
   with TSecondForm.Create(Self) do
   try
     if ShowModal = mrOK then
        MyProcedure(ParamA,ParamB);
   finally
     Free;
   end;
end;

ParamA следует понимать как SecondForm.ParamA

Wolfgan 17 Junior Poster

Help reading have not tried it? DWORD is equivalent to LongWord.

uses
   MPlayer, MMSystem, Types;

or replace DWORD on LongWord. Everything works fine. I attach a file for example.

Wolfgan 17 Junior Poster
uses
   MPlayer, MMSystem;
 
 const
   MCI_SETAUDIO = $0873;
   MCI_DGV_SETAUDIO_VOLUME = $4002;
   MCI_DGV_SETAUDIO_ITEM = $00800000;
   MCI_DGV_SETAUDIO_VALUE = $01000000;
   MCI_DGV_STATUS_VOLUME = $4019;
 
 type
   MCI_DGV_SETAUDIO_PARMS = record
     dwCallback: DWORD;
     dwItem: DWORD;
     dwValue: DWORD;
     dwOver: DWORD;
     lpstrAlgorithm: PChar;
     lpstrQuality: PChar;
   end;
 
 type
   MCI_STATUS_PARMS = record
     dwCallback: DWORD;
     dwReturn: DWORD;
     dwItem: DWORD;
     dwTrack: DWORD;
   end;
 
 procedure SetMPVolume(MP: TMediaPlayer; Volume: Integer);
   { Volume: 0 - 1000 }
 var
   p: MCI_DGV_SETAUDIO_PARMS;
 begin
   { Volume: 0 - 1000 }
   p.dwCallback := 0;
   p.dwItem := MCI_DGV_SETAUDIO_VOLUME;
   p.dwValue := Volume;
   p.dwOver := 0;
   p.lpstrAlgorithm := nil;
   p.lpstrQuality := nil;
   mciSendCommand(MP.DeviceID, MCI_SETAUDIO,
     MCI_DGV_SETAUDIO_VALUE or MCI_DGV_SETAUDIO_ITEM, Cardinal(@p));
 end;
 
 function GetMPVolume(MP: TMediaPlayer): Integer;
 var
    p: MCI_STATUS_PARMS;
 begin
   p.dwCallback := 0;
   p.dwItem := MCI_DGV_STATUS_VOLUME;
   mciSendCommand(MP.DeviceID, MCI_STATUS, MCI_STATUS_ITEM, Cardinal(@p));
   Result := p.dwReturn;
   { Volume: 0 - 1000 }
 end;
 
 // Example, Beispiel: 
 
procedure TForm1.Button1Click(Sender: TObject);
 begin
   SetMPVolume(MediaPlayer1, 500);
 end;
Wolfgan 17 Junior Poster

Possible. Just a little bit differently.

TBookName = string[20];
TPDFLink  = string[200];
BookLibrary = record
    AuthorName: String[20];
    BookName:   Array[1..20] of TBookName;
    PDFLink:    Array[1..20] of TPDFLink;
end;
Wolfgan 17 Junior Poster

Then it is better to use INI files. But this is not the best option.

var
  i,j: integer;
begin
  with TIniFile.Create(ExtractFilePath(ParamStr(0))+'Filename.txt') do
  try
    for i := 0 to self.ControlCount-1 do
      if (self.Controls[i] is TEdit) then
          WriteString(self.Controls[i].Name,'Value',(self.Controls[i] as TEdit).Text)
      else
      if (self.Controls[i] is TMemo) then
         for j := 0 to (self.Controls[i] as TMemo).Lines.Count - 1 do
           WriteString(self.Controls[i].Name,'Line'+intToStr(j),(self.Controls[i] as TMemo).Lines[j]);
  finally
    Free;
  end;
var
  i,j,idx: integer;
  StrList: TStringList;
begin
  with TIniFile.Create(ExtractFilePath(ParamStr(0))+'Filename.txt') do
  try
    for i := 0 to self.ControlCount-1 do
     if (self.Controls[i] is TEdit) then
        (self.Controls[i] as TEdit).Text := ReadString(self.Controls[i].Name,'Value','')
     else
     if (self.Controls[i] is TMemo) then
     begin
       StrList := TStringList.Create;
       try
         ReadSectionValues(self.Controls[i].Name,StrList);
         (self.Controls[i] as TMemo).Clear;
         for j := 0 to StrList.Count - 1 do
           (self.Controls[i] as TMemo).Lines.Add(StrList.ValueFromIndex[j]);
       finally
         StrList.Free;
       end;
     end;
  finally
    Free;
  end;
Wolfgan 17 Junior Poster

Yes. Easy.

Save:

procedure TForm1.SaveButtonClick(Sender: TObject);
var
  i: integer;
begin
  with TStringList.Create do
  try
    for i := 0 to self.ControlCount-1 do
      if (self.Controls[i] is TEdit) then
          Add(self.Controls[i].Name+'='+(self.Controls[i] as TEdit).Text);
    SaveToFile('Filename.txt');
  finally
    Free;
  end;
end;

load:

procedure TForm1.LoadButtonClick(Sender: TObject);
var
  i,idx: integer;
begin
  with TStringList.Create do
  try
    LoadFromFile('Filename.txt');
    for i := 0 to self.ControlCount-1 do
    begin
      idx := IndexOfName(self.Controls[i].Name);
      if idx <> -1 then
         (self.Controls[i] as TEdit).Text := ValueFromIndex[idx];
    end;
  finally
    Free;
  end;
end;
Wolfgan 17 Junior Poster

Bitmap to Icon:
We need to create two bitmap: bitmap-mask ("AND" bitmap) and bitmap-image (XOR bitmap). Then transmit descriptors "AND" and "XOR" bitmap-s API functions CreateIconIndirect ():

procedure TForm1.Button1Click(Sender: TObject);
var
  IconSizeX: integer;
  IconSizeY: integer;
  AndMask: TBitmap;
  XOrMask: TBitmap;
  IconInfo: TIconInfo;
  Icon: TIcon;
begin
  {Get the icon size}
  IconSizeX := GetSystemMetrics(SM_CXICON);
  IconSizeY := GetSystemMetrics(SM_CYICON);
  {Create the "And" mask}
  AndMask := TBitmap.Create;
  AndMask.Monochrome := true;
  AndMask.Width := IconSizeX;
  AndMask.Height := IconSizeY;
  {Draw on the "And" mask}
  AndMask.Canvas.Brush.Color := clWhite;
  AndMask.Canvas.FillRect(Rect(0, 0, IconSizeX, IconSizeY));
  AndMask.Canvas.Brush.Color := clBlack;
  AndMask.Canvas.Ellipse(4, 4, IconSizeX - 4, IconSizeY - 4);
  {Draw as a test}
  Form1.Canvas.Draw(IconSizeX * 2, IconSizeY, AndMask);
  {Create the "XOr" mask}
  XOrMask := TBitmap.Create;
  XOrMask.Width := IconSizeX;
  XOrMask.Height := IconSizeY;
  {Draw on the "XOr" mask}
  XOrMask.Canvas.Brush.Color := ClBlack;
  XOrMask.Canvas.FillRect(Rect(0, 0, IconSizeX, IconSizeY));
  XOrMask.Canvas.Pen.Color := clRed;
  XOrMask.Canvas.Brush.Color := clRed;
  XOrMask.Canvas.Ellipse(4, 4, IconSizeX - 4, IconSizeY - 4);
  {Draw as a test}
  Form1.Canvas.Draw(IconSizeX * 4, IconSizeY, XOrMask);
  {Create a icon}
  Icon := TIcon.Create;
  IconInfo.fIcon := true;
  IconInfo.xHotspot := 0;
  IconInfo.yHotspot := 0;
  IconInfo.hbmMask := AndMask.Handle;
  IconInfo.hbmColor := XOrMask.Handle;
  Icon.Handle := CreateIconIndirect(IconInfo);
  {Destroy the temporary bitmaps}
  AndMask.Free;
  XOrMask.Free;
  {Draw as a test}
  Form1.Canvas.Draw(IconSizeX * 6, IconSizeY, Icon);
  {Assign the application icon}
  Application.Icon := Icon;
  {Force a repaint}
  InvalidateRect(Application.Handle, nil, true);
  {Free the icon}
  Icon.Free;
end;
Wolfgan 17 Junior Poster

1.Make cursor in cursor editor (hand.cur).
2.Make text file "cursors.rc": HAND CURSOR HAND.CUR
3.Compile: "C:\Program Files\CodeGear\RAD Studio\6.0\bin\brcc32.exe" cursor.rc
4.In program:

const
  crHand  = 10;
....
implementation
{$R Cursor.res}
.....
procedure TForm1.Create(Owner: TObject);
begin
  Screen.Cursors[crHand]  := LoadCursor(hInstance,'HAND');
end;
...
uses:
  Screen.Cursor := crHand;
Wolfgan 17 Junior Poster

Maybe this will help http://www.alphaskins.com/