Browse Source

FEATURE: loading examples from the internet.

Wilfried Klaas 5 years ago
parent
commit
0227dd3d5c
3 changed files with 86 additions and 21 deletions
  1. 7 0
      blink.tps
  2. 20 20
      ugui.lfm
  3. 59 1
      ugui.pas

+ 7 - 0
blink.tps

@@ -0,0 +1,7 @@
+#TPS:Willies SPS Arduino
+0x00,1,5,""
+0x01,2,8,""
+0x02,1,A,""
+0x03,2,8,""
+0x04,3,4,""
+0x05,0,0,""

+ 20 - 20
ugui.lfm

@@ -720,43 +720,43 @@ object Form1: TForm1
       ShowHint = True
     end
     object ToolButton2: TToolButton
-      Left = 71
+      Left = 73
       Top = 2
       Action = acFileOpen
     end
     object ToolButton3: TToolButton
-      Left = 95
+      Left = 97
       Top = 2
       Action = acFileSave
       Caption = 'ID_SAVE'
     end
     object ToolButton4: TToolButton
-      Left = 255
+      Left = 257
       Height = 22
       Top = 2
       Caption = 'ToolButton4'
       Style = tbsSeparator
     end
     object ToolButton6: TToolButton
-      Left = 287
+      Left = 289
       Top = 2
       Action = acNextStep
       Caption = 'ID_EXEC_NEXT'
     end
     object ToolButton7: TToolButton
-      Left = 311
+      Left = 313
       Top = 2
       Action = acStop
       Caption = 'ID_EXEC_STOP'
     end
     object ToolButton5: TToolButton
-      Left = 335
+      Left = 337
       Top = 2
       Action = acDebug
       Caption = 'ID_EXEC_DEBUG'
     end
     object cbTPSVersion: TComboBox
-      Left = 455
+      Left = 457
       Height = 23
       Top = 2
       Width = 125
@@ -772,7 +772,7 @@ object Form1: TForm1
       TabOrder = 0
     end
     object Label3: TLabel
-      Left = 367
+      Left = 369
       Height = 15
       Top = 2
       Width = 88
@@ -782,33 +782,33 @@ object Form1: TForm1
       ParentColor = False
     end
     object ToolButton8: TToolButton
-      Left = 359
+      Left = 361
       Height = 22
       Top = 2
       Caption = 'ToolButton8'
       Style = tbsSeparator
     end
     object ToolButton9: TToolButton
-      Left = 263
+      Left = 265
       Top = 2
       Action = acThisStep
       Caption = 'ID_EXEC_STATEMENT'
     end
     object ToolButton10: TToolButton
-      Left = 183
+      Left = 185
       Top = 2
       Action = acShowHexFile
       Caption = 'ID_PRGFILE'
     end
     object ToolButton11: TToolButton
-      Left = 175
+      Left = 177
       Height = 22
       Top = 2
       Caption = 'ToolButton11'
       Style = tbsSeparator
     end
     object ToolButton12: TToolButton
-      Left = 207
+      Left = 209
       Top = 2
       Action = acUpload
       Caption = 'ID_PRGULOAD'
@@ -819,38 +819,38 @@ object Form1: TForm1
       Action = acNew
     end
     object ToolButton14: TToolButton
-      Left = 119
+      Left = 121
       Height = 22
       Top = 2
       Caption = 'ToolButton14'
       Style = tbsSeparator
     end
     object ToolButton15: TToolButton
-      Left = 127
+      Left = 129
       Top = 2
       Action = acNewRow
       Caption = 'ID_NEWLINE'
     end
     object ToolButton16: TToolButton
-      Left = 151
+      Left = 153
       Top = 2
       Action = acDeleteRow
       Caption = 'ID_DELLINE'
     end
     object ToolButton17: TToolButton
-      Left = 580
+      Left = 582
       Height = 22
       Top = 2
       Caption = 'ToolButton17'
       Style = tbsDivider
     end
     object ToolButton18: TToolButton
-      Left = 585
+      Left = 587
       Top = 2
       Action = acHelpAbout
     end
     object MCSLabel: TLabel
-      Left = 609
+      Left = 611
       Height = 22
       Top = 2
       Width = 20
@@ -861,7 +861,7 @@ object Form1: TForm1
       OnClick = MCSLabelClick
     end
     object ToolButton19: TToolButton
-      Left = 231
+      Left = 233
       Top = 2
       Action = acHexFile
       Caption = 'ID_HEXFILE'

+ 59 - 1
ugui.pas

@@ -189,6 +189,7 @@ type
     Examples : TStringList;
     procedure initMidi;
     procedure playNote(note: byte);
+    procedure loadFromList(lines : TStringlist; filename : String);
     function readString(var line: string): boolean;
     procedure saveSection(filename: string; key: string);
     procedure loadSection(filename: string; key: string);
@@ -299,6 +300,53 @@ begin
   lastNote := note;
 end;
 
+procedure TForm1.loadFromList(lines: TStringlist; filename : String);
+var
+  i,x: integer;
+  line: string;
+  list: TStringList;
+begin
+  acNew.Execute;
+  list := TStringList.Create;
+  i := 1;
+  for x := 0 to lines.count-1 do begin
+    if (i + 1 > StringGrid1.RowCount) then
+    begin
+      StringGrid1.RowCount := StringGrid1.RowCount + 1;
+    end;
+    line :=  lines[x];
+    if (Pos('#', line) = 1) then
+    begin
+      line := RightstrPos(line, 2);
+      if (Pos('TPS:', line) = 1) then
+      begin
+        line := RightstrPos(line, 5);
+        cbTPSVersion.Text := line;
+        cbTPSVersionChange(nil);
+      end;
+    end else
+    begin
+      MCSStrings.DelimSepTextToStringlist(line, '"', ',', list);
+      if list.Count > 0 then
+        Stringgrid1.Cells[0, i] := list[0];
+      if list.Count > 1 then
+        Stringgrid1.Cells[1, i] := list[1];
+      if list.Count > 2 then
+        Stringgrid1.Cells[2, i] := list[2];
+      if list.Count > 3 then
+        Stringgrid1.Cells[4, i] := list[3];
+      list.Clear;
+      inc(i);
+    end;
+  end;
+  list.Free;
+  activeFile := filename;
+  renumberGrid();
+  addHeaderText;
+  setCaption();
+  setDirty(False);
+end;
+
 procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
 var
   line: string;
@@ -317,10 +365,20 @@ end;
 
 procedure TForm1.MenuItem1Click(Sender: TObject);
 var i : integer;
+    fileName, data : String;
+    lines : TStringList;
 begin
   // todo
   if (Sender is TMenuItem) then begin
-    i := TMenuItem(Sender).Tag;
+    if (checkDirty()) then begin
+      i := TMenuItem(Sender).Tag;
+      filename :=  examples[i-1];
+      data := DownloadFile('http://wkla.no-ip.biz/down/' + filename);
+      lines := TStringList.Create;
+      lines.Text:= data;
+      loadFromList(lines, filename);
+      lines.Free;
+    end;
   end;
 end;