pascal和Delphi初使用

今日需求给Delphi(RAD Studio开发工具)应用添加2个控件:图片框和输入框
要求把接口得到的两个数据渲染到这2个控件上。

Pascal 语言中的关键字及保留字
Pascal 教程 - 蝴蝶教程
Pascal - 基本语法 在线实例教程 - IT屋
Delphi教程(完整版)
25 岁的老 Delphi,还值得程序员入手吗?
Delphi编程技巧大全
delphi XE 和 RAD studio有什么区别_360问答
RAD Studio 10 Seattle 第21-4课 窗体组件详解: 按钮类组件-教育-高清完整正版视频在线观看-优酷

Pascal的基本结构

program {name of the program 程序的名称}
uses {comma delimited names of libraries you use 用逗号分隔的使用的库的名称}
const {global constant declaration block 全局常量声明块}
var {global variable declaration block 全局变量声明块}

function {function declarations, if any 函数声明(如果有)}
{ local variables 局部变量}
begin
...
end;

procedure { procedure declarations, if any 程序声明(如有)}
{ local variables }
begin
...
end;

begin { main program block starts 主程序块启动}
...
end. { the end of main program block 主程序块的结尾}

Pascal的数据类型

(*
  type-identifier-1, type-identfier-2 = type-specifier;
  以下声明将变量day和age定义为整数类型
         将yes和true定义为布尔类型
         将name和city定义为字符串类型
         将fees和expenses定义为实数类型  *)
type
days, age = integer;
yes, true = boolean;
name, city = string;
fees, expenses = real;

Pascal的变量声明

把从接口得到的JSON数据,提取出指定数据,渲染到指定的编辑框里

delphi – 如何读取和更改TEdit控件的值? - 编程之家
Delphi 之 编辑框控件(TEdit) - Delphi爱好者2014 - 博客园
Delphi 与 JSON - 随笔分类 - 万一 - 博客园
Delphi10.3读取JSON数组
delphi 自带JSON的用法

最终解决:把json中的data也作为TJSONObject类型。然后直接拿里面的值。
参考delphi自带的Json单元读取Json用MJson .GetValue(‘path’)之后使用了泛型。

procedure TForm1.Button2Click(Sender: TObject);
var
  requestRet:String;
  jsonObject :TJSONObject;
  data:TJSONObject;
  img:String;
  temperature:String;
begin
  requestRet := requestHelper.getRequest('http://localhost:8099/fkxt/delphi');
  jsonObject := TJSONObject.ParseJSONValue(requestRet) as TJSONObject;
  if jsonObject.getValue('state').toString() <> '1000' then
  begin
    MessageBox(0,PWideChar(jsonObject.GetValue('msg').ToString()),'失败',MB_OK);
  end;
  data := jsonObject.GetValue('data') as TJSONObject;
  img := data.GetValue<String>('img');
  temperature := data.GetValue<String>('temperature');
  Edit1.Text := img;
  Edit2.Text := temperature;
  //MessageBox(0,PWideChar(jsonObject.GetValue('data').ToString()),'结果',MB_OK);
end;
posted @ 2021-03-04 14:32  张三丰学Java  阅读(269)  评论(0编辑  收藏  举报