XE3随笔10:TSuperType
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses SuperObject;
//类型
procedure TForm1.Button1Click(Sender: TObject);
function GetJsonType(I: ISuperObject): string;
begin
case I.DataType of
stNull: Result := 'stNull';
stBoolean: Result := 'stBoolean';
stDouble: Result := 'stDouble';
stInt: Result := 'stInt';
stObject: Result := 'stObject';
stArray: Result := 'stArray';
stString: Result := 'stString';
stMethod: Result := 'stMethod';
end;
end;
var
jo: ISuperObject;
begin
jo := SO('{A:1, B:2}');
ShowMessage(GetJsonType(jo)); {stObject}
jo := SO;
ShowMessage(GetJsonType(jo)); {stObject}
jo := SO('abc');
ShowMessage(GetJsonType(jo)); {stString}
jo := SO(123);
ShowMessage(GetJsonType(jo)); {stInt}
jo := SO('123');
ShowMessage(GetJsonType(jo)); {stInt}
jo := SO(3.14);
ShowMessage(GetJsonType(jo)); {stDouble}
jo := SO('3.14');
ShowMessage(GetJsonType(jo)); {stDouble}
jo := SO(False);
ShowMessage(GetJsonType(jo)); {stBoolean}
jo := SO('[1,2,3,a,b,c]');
ShowMessage(GetJsonType(jo)); {stArray}
jo := TSuperObject.Create(stMethod);
ShowMessage(GetJsonType(jo)); {stMethod}
jo := SO('null');
ShowMessage(GetJsonType(jo)); {stNull}
end;
//判断
procedure TForm1.Button2Click(Sender: TObject);
var
jo: ISuperObject;
begin
jo := SO('[]');
if jo.DataType = stArray then ShowMessage('stArray');
if ObjectIsType(jo, stArray) then ShowMessage('stArray');
end;
end.
XE3随笔10:TSuperType的更多相关文章
- XE3随笔20:几个和当前路径相关的新函数
偶然从 SysUtils 里发现了几个路径相关的函数, 以前没见过, 可能是 Delphi XE3 新增的: GetLocaleDirectory(); GetLocaleFile(); Locale ...
- XE3随笔6:SuperObject 的 JSON 对象中还可以包含 "方法"
SuperObject 的 JSON 对象中还可以包含 "方法", 这太有意思了; 其方法的格式是: procedure Method(const This, Params: IS ...
- hibernate注解随笔—10月8日
hibernate注解(herbinate4 jar包注解可用,使用hibernate3.3注解失败) 如果javabean与数据库中表名一致(不区分大小写),则注解不用写@Table(name=&q ...
- XE3随笔21:系统默认语言与系统支持的语言列表
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...
- XE3随笔18:实例 - 解析 Google 关键字搜索排名
同上例类似, 通过 'http://clients1.google.cn/complete/search?&q=' + "关键字" 可以获取 Google 的关键字搜索排名 ...
- XE3随笔19:实例 - 借用 Google 实现全文翻译
调用 Google 翻译的地址格式: http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + ...
- XE3随笔17:实例 - 模拟 Google 搜索
本例测试效果图: 代码文件: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics ...
- XE3随笔16:将字符串转换成 UTF8 编码的函数
这种转换一般用于网页地址; 我不知道 Delphi 是不是有现成的函数, 用到了就写了一个. //函数: function ToUTF8Encode(str: string): string; var ...
- XE3随笔15:使用 IXMLHTTPRequest 简单获取网页源代码
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...
随机推荐
- ADO.NET数据库操作助手类
SQL语句操作增删查改助手类 using System; using System.Collections.Generic; using System.Configuration; using Sys ...
- My WelcomeApplet
import java.applet.*; import java.awt.*; import java.awt.event.*; public class WelcomeApplet extends ...
- Java多线程-线程的同步与锁
一.同步问题提出 线程的同步是为了防止多个线程访问一个数据对象时,对数据造成的破坏.例如:两个线程ThreadA.ThreadB都操作同一个对象Foo对象,并修改Foo对象上的数据. package ...
- mvc view-controller mvc annotation-driven
1.mvc view-controller 使页面直接通过某个连接跳转,不进过mvc handler 需要加一个配置 <mvc : view-controller path="/suc ...
- [CF442B] Andrey and Problem (概率dp)
题目链接:http://codeforces.com/problemset/problem/442/B 题目大意:有n个人,第i个人出一道题的概率是pi,现在选出一个子集,使得这些人恰好出一个题的概率 ...
- [poj1860] Currency Exchange (bellman-ford算法)
题目链接:http://poj.org/problem?id=1860 题目大意:给你一些兑换方式,问你能否通过换钱来赚钱? 使用ford算法,当出现赚钱的时候就返回YES,如果不能赚钱,则返回NO ...
- 10. Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- [清理页面缓存]asp.net、html
(1) MVC BaseController: Controller内 protected override void Initialize(System.Web.Routing.RequestC ...
- SQL笔记 [SQL判断是否存在] [长期更新] (-2015.4)
--判断某个存储过程是否存在if exists (select * from sysobjects where id = object_id(N'[p_CreateTable]') and OBJEC ...
- Linux防火墙
9.1 认识防火墙 只要能够分析与过滤进出我们管理之网域的封包数据, 就可以称为防火墙. 硬件防火墙 由厂商设计好的主机硬件, 这部硬件防火墙内的操作系统主要以提供封包数据的过滤机制为主,并将其他 ...